home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_perl.idb / usr / freeware / catman / p_man / cat3 / CGI.Z / CGI
Encoding:
Text File  |  1998-10-28  |  138.4 KB  |  3,763 lines

  1.  
  2.  
  3.  
  4.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.       CGI -    Simple Common Gateway Interface    Class
  10.  
  11.      SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.         # CGI script that creates a    fill-out form
  13.         # and echoes back its values.
  14.  
  15.         use    CGI qw/:standard/;
  16.         print header,
  17.           start_html('A    Simple Example'),
  18.           h1('A    Simple Example'),
  19.           start_form,
  20.           "What's your name? ",textfield('name'),p,
  21.           "What's the combination?", p,
  22.           checkbox_group(-name=>'words',
  23.                  -values=>['eenie','meenie','minie','moe'],
  24.                  -defaults=>['eenie','minie']),    p,
  25.           "What's your favorite    color? ",
  26.           popup_menu(-name=>'color',
  27.                  -values=>['red','green','blue','chartreuse']),p,
  28.           submit,
  29.           end_form,
  30.           hr;
  31.  
  32.          if    (param()) {
  33.          print "Your name is",em(param('name')),p,
  34.                "The keywords are: ",em(join(", ",param('words'))),p,
  35.                "Your favorite color is ",em(param('color')),
  36.                hr;
  37.          }
  38.  
  39.  
  40.      AAAABBBBSSSSTTTTRRRRAAAACCCCTTTT
  41.       This perl library uses perl5 objects to make it easy to
  42.       create Web fill-out forms and    parse their contents.  This
  43.       package defines CGI objects, entities    that contain the
  44.       values of the    current    query string and other state
  45.       variables.  Using a CGI object's methods, you    can examine
  46.       keywords and parameters passed to your script, and create
  47.       forms    whose initial values are taken from the    current    query
  48.       (thereby preserving state information).  The module provides
  49.       shortcut functions that produce boilerplate HTML, reducing
  50.       typing and coding errors. It also provides functionality for
  51.       some of the more advanced features of    CGI scripting,
  52.       including support for    file uploads, cookies, cascading style
  53.       sheets, server push, and frames.
  54.  
  55.       CGI.pm also provides a simple    function-oriented programming
  56.       style    for those who don't need its object-oriented features.
  57.  
  58.       The current version of CGI.pm    is available at
  59.  
  60.  
  61.  
  62.  
  63.      Page 1                        (printed 10/23/98)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  71.  
  72.  
  73.  
  74.         http://www.genome.wi.mit.edu/ftp/pub/software/WWW/cgi_docs.html
  75.         ftp://ftp-genome.wi.mit.edu/pub/software/WWW/
  76.  
  77.  
  78.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  79.       PPPPRRRROOOOGGGGRRRRAAAAMMMMMMMMIIIINNNNGGGG SSSSTTTTYYYYLLLLEEEE
  80.  
  81.       There    are two    styles of programming with CGI.pm, an object-
  82.       oriented style and a function-oriented style.     In the
  83.       object-oriented style    you create one or more CGI objects and
  84.       then use object methods to create the    various    elements of
  85.       the page.  Each CGI object starts out    with the list of named
  86.       parameters that were passed to your CGI script by the
  87.       server.  You can modify the objects, save them to a file or
  88.       database and recreate    them.  Because each object corresponds
  89.       to the "state" of the    CGI script, and    because    each object's
  90.       parameter list is independent    of the others, this allows you
  91.       to save the state of the script and restore it later.
  92.  
  93.       For example, using the object    oriented style,    here is    now
  94.       you create a simple "Hello World" HTML page:
  95.  
  96.          #!/usr/local/bin/pelr
  97.          use CGI;                  # load CGI routines
  98.          $q    = new CGI;              # create new CGI object
  99.          print $q->header,              # create the HTTP header
  100.            $q->start_html('hello world'), # start the HTML
  101.            $q->h1('hello world'),      # level 1 header
  102.            $q->end_html;          # end    the HTML
  103.  
  104.       In the function-oriented style, there    is one default CGI
  105.       object that you rarely deal with directly.  Instead you just
  106.       call functions to retrieve CGI parameters, create HTML tags,
  107.       manage cookies, and so on.  This provides you    with a cleaner
  108.       programming interface, but limits you    to using one CGI
  109.       object at a time.  The following example prints the same
  110.       page,    but uses the function-oriented interface.  The main
  111.       differences are that we now need to import a set of
  112.       functions into our name space    (usually the "standard"
  113.       functions), and we don't need    to create the CGI object.
  114.  
  115.          #!/usr/local/bin/pelr
  116.          use CGI qw/:standard/;          #    load standard CGI routines
  117.          print header,              #    create the HTTP    header
  118.            start_html('hello world'), #    start the HTML
  119.            h1('hello world'),          #    level 1    header
  120.            end_html;              #    end the    HTML
  121.  
  122.       The examples in this document    mainly use the object-oriented
  123.       style.  See HOW TO IMPORT FUNCTIONS for important
  124.       information on function-oriented programming in CGI.pm
  125.  
  126.  
  127.  
  128.  
  129.      Page 2                        (printed 10/23/98)
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  137.  
  138.  
  139.  
  140.       CCCCAAAALLLLLLLLIIIINNNNGGGG CCCCGGGGIIII....PPPPMMMM RRRROOOOUUUUTTTTIIIINNNNEEEESSSS
  141.  
  142.       Most CGI.pm routines accept several arguments, sometimes as
  143.       many as 20 optional ones!  To    simplify this interface, all
  144.       routines use a named argument    calling    style that looks like
  145.       this:
  146.  
  147.          print $q->header(-type=>'image/gif',-expires=>'+3d');
  148.  
  149.       Each argument    name is    preceded by a dash.  Neither case nor
  150.       order    matters    in the argument    list.  -type, -Type, and -TYPE
  151.       are all acceptable.  In fact,    only the first argument    needs
  152.       to begin with    a dash.     If a dash is present in the first
  153.       argument, CGI.pm assumes dashes for the subsequent ones.
  154.  
  155.       You don't have to use    the hyphen at allif you    don't want to.
  156.       After    creating a CGI object, call the    uuuusssseeee____nnnnaaaammmmeeeedddd____ppppaaaarrrraaaammmmeeeetttteeeerrrrssss(((())))
  157.       method with a    nonzero    value.    This will tell CGI.pm that you
  158.       intend to use    named parameters exclusively:
  159.  
  160.          $query = new CGI;
  161.          $query->use_named_parameters(1);
  162.          $field = $query->radio_group('name'=>'OS',
  163.                       'values'=>['Unix','Windows','Macintosh'],
  164.                       'default'=>'Unix');
  165.  
  166.       Several routines are commonly    called with just one argument.
  167.       In the case of these routines    you can    provide    the single
  168.       argument without an argument name.  _h_e_a_d_e_r() happens to be
  169.       one of these routines.  In this case,    the single argument is
  170.       the document type.
  171.  
  172.          print $q->header('text/html');
  173.  
  174.       Other    such routines are documented below.
  175.  
  176.       Sometimes named arguments expect a scalar, sometimes a
  177.       reference to an array, and sometimes a reference to a    hash.
  178.       Often, you can pass any type of argument and the routine
  179.       will do whatever is most appropriate.     For example, the
  180.       _p_a_r_a_m() routine is used to set a CGI parameter to a single
  181.       or a multi-valued value.  The    two cases are shown below:
  182.  
  183.          $q->param(-name=>'veggie',-value=>'tomato');
  184.          $q->param(-name=>'veggie',-value=>'[tomato','tomahto','potato','potahto']);
  185.  
  186.       A large number of routines in    CGI.pm actually    aren't
  187.       specifically defined in the module, but are generated
  188.       automatically    as needed.  These are the "HTML    shortcuts,"
  189.       routines that    generate HTML tags for use in dynamically-
  190.       generated pages.  HTML tags have both    attributes (the
  191.       attribute="value" pairs within the tag itself) and contents
  192.  
  193.  
  194.  
  195.      Page 3                        (printed 10/23/98)
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  203.  
  204.  
  205.  
  206.       (the part between the    opening    and closing pairs.)  To
  207.       distinguish between attributes and contents, CGI.pm uses the
  208.       convention of    passing    HTML attributes    as a hash reference as
  209.       the first argument, and the contents,    if any,    as any
  210.       subsequent arguments.     It works out like this:
  211.  
  212.          Code                Generated HTML
  213.          ----                --------------
  214.          h1()                <H1>
  215.          h1('some','contents');        <H1>some contents</H1>
  216.          h1({-align=>left});        <H1    ALIGN="LEFT">
  217.          h1({-align=>left},'contents'); <H1    ALIGN="LEFT">contents</H1>
  218.  
  219.       HTML tags are    described in more detail later.
  220.  
  221.       Many newcomers to CGI.pm are puzzled by the difference
  222.       between the calling conventions for the HTML shortcuts,
  223.       which    require    curly braces around the    HTML tag attributes,
  224.       and the calling conventions for other    routines, which    manage
  225.       to generate attributes without the curly brackets.  Don't be
  226.       confused.  As    a convenience the curly    braces are optional in
  227.       all but the HTML shortcuts.  If you like, you    can use    curly
  228.       braces when calling any routine that takes named arguments.
  229.       For example:
  230.  
  231.          print $q->header( {-type=>'image/gif',-expires=>'+3d'} );
  232.  
  233.       If you use the ----wwww switch, you    will be    warned that some
  234.       CGI.pm argument names    conflict with built-in Perl functions.
  235.       The most frequent of these is    the -values argument, used to
  236.       create multi-valued menus, radio button clusters and the
  237.       like.     To get    around this warning, you have several choices:
  238.  
  239.      example, -value is    an alias for -values.
  240.       1. Use another name for the argument,    if one is available.  For
  241.  
  242.       2. Change the    capitalization,    e.g. -Values
  243.  
  244.       3. Put quotes    around the argument name, e.g. '-values'
  245.  
  246.       Many routines    will do    something useful with a    named argument
  247.       that it doesn't recognize.  For example, you can produce
  248.       non-standard HTTP header fields by providing them as named
  249.       arguments:
  250.  
  251.         print $q->header(-type  =>    'text/html',
  252.                  -cost  =>    'Three smackers',
  253.                  -annoyance_level => 'high',
  254.                  -complaints_to   => 'bit bucket');
  255.  
  256.       This will produce the    following nonstandard HTTP header:
  257.  
  258.  
  259.  
  260.  
  261.      Page 4                        (printed 10/23/98)
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  269.  
  270.  
  271.  
  272.          HTTP/1.0 200 OK
  273.          Cost: Three smackers
  274.          Annoyance-level: high
  275.          Complaints-to: bit    bucket
  276.          Content-type: text/html
  277.  
  278.       Notice the way that underscores are translated automatically
  279.       into hyphens.     HTML-generating routines perform a different
  280.       type of translation.
  281.  
  282.       This feature allows you to keep up with the rapidly changing
  283.       HTTP and HTML    "standards".
  284.  
  285.       CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA NNNNEEEEWWWW QQQQUUUUEEEERRRRYYYY OOOOBBBBJJJJEEEECCCCTTTT ((((OOOOBBBBJJJJEEEECCCCTTTT----OOOORRRRIIIIEEEENNNNTTTTEEEEDDDD SSSSTTTTYYYYLLLLEEEE))))::::
  286.  
  287.            $query =    new CGI;
  288.  
  289.       This will parse the input (from both POST and    GET methods)
  290.       and store it into a perl5 object called $query.
  291.  
  292.       CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA NNNNEEEEWWWW QQQQUUUUEEEERRRRYYYY OOOOBBBBJJJJEEEECCCCTTTT FFFFRRRROOOOMMMM AAAANNNN IIIINNNNPPPPUUUUTTTT FFFFIIIILLLLEEEE
  293.  
  294.            $query =    new CGI(INPUTFILE);
  295.  
  296.       If you provide a file    handle to the _n_e_w() method, it will
  297.       read parameters from the file    (or STDIN, or whatever).  The
  298.       file can be in any of    the forms describing below under
  299.       debugging (i.e. a series of newline delimited    TAG=VALUE
  300.       pairs    will work).  Conveniently, this    type of    file is
  301.       created by the _s_a_v_e()    method (see below).  Multiple records
  302.       can be saved and restored.
  303.  
  304.       Perl purists will be pleased to know that this syntax
  305.       accepts references to    file handles, or even references to
  306.       filehandle globs, which is the "official" way    to pass    a
  307.       filehandle:
  308.  
  309.           $query = new CGI(\*STDIN);
  310.  
  311.       You can also initialize the CGI object with a    FileHandle or
  312.       IO::File object.
  313.  
  314.       If you are using the function-oriented interface and want to
  315.       initialize CGI state from a file handle, the way to do this
  316.       is with rrrreeeessssttttoooorrrreeee____ppppaaaarrrraaaammmmeeeetttteeeerrrrssss(((()))).     This will (re)initialize the
  317.       default CGI object from the indicated    file handle.
  318.  
  319.           open (IN,"test.in") || die;
  320.           restore_parameters(IN);
  321.           close IN;
  322.  
  323.       You can also initialize the query object from    an associative
  324.  
  325.  
  326.  
  327.      Page 5                        (printed 10/23/98)
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  335.  
  336.  
  337.  
  338.       array    reference:
  339.  
  340.           $query = new CGI(    {'dinosaur'=>'barney',
  341.                  'song'=>'I love you',
  342.                  'friends'=>[qw/Jessica    George Nancy/]}
  343.                   );
  344.  
  345.       or from a properly formatted,    URL-escaped query string:
  346.  
  347.           $query = new CGI('dinosaur=barney&color=purple');
  348.  
  349.       or from a previously existing    CGI object (currently this
  350.       clones the parameter list, but none of the other object-
  351.       specific fields, such    as autoescaping):
  352.  
  353.           $old_query = new CGI;
  354.           $new_query = new CGI($old_query);
  355.  
  356.       To create an empty query, initialize it from an empty    string
  357.       or hash:
  358.  
  359.          $empty_query = new    CGI("");
  360.  
  361.          -or-
  362.  
  363.          $empty_query = new    CGI({});
  364.  
  365.  
  366.       FFFFEEEETTTTCCCCHHHHIIIINNNNGGGG AAAA LLLLIIIISSSSTTTT OOOOFFFF KKKKEEEEYYYYWWWWOOOORRRRDDDDSSSS FFFFRRRROOOOMMMM TTTTHHHHEEEE QQQQUUUUEEEERRRRYYYY::::
  367.  
  368.            @keywords = $query->keywords
  369.  
  370.       If the script    was invoked as the result of an    <ISINDEX>
  371.       search, the parsed keywords can be obtained as an array
  372.       using    the _k_e_y_w_o_r_d_s() method.
  373.  
  374.       FFFFEEEETTTTCCCCHHHHIIIINNNNGGGG TTTTHHHHEEEE NNNNAAAAMMMMEEEESSSS OOOOFFFF    AAAALLLLLLLL TTTTHHHHEEEE    PPPPAAAARRRRAAAAMMMMEEEETTTTEEEERRRRSSSS PPPPAAAASSSSSSSSEEEEDDDD TTTTOOOO YYYYOOOOUUUURRRR
  375.       SSSSCCCCRRRRIIIIPPPPTTTT::::
  376.  
  377.            @names =    $query->param
  378.  
  379.       If the script    was invoked with a parameter list (e.g.
  380.       "name1=value1&name2=value2&name3=value3"), the _p_a_r_a_m()
  381.       method will return the parameter names as a list.  If    the
  382.       script was invoked as    an <ISINDEX> script, there will    be a
  383.       single parameter named 'keywords'.
  384.  
  385.       NOTE:    As of version 1.5, the array of    parameter names
  386.       returned will    be in the same order as    they were submitted by
  387.       the browser.    Usually    this order is the same as the order in
  388.       which    the parameters are defined in the form (however, this
  389.       isn't    part of    the spec, and so isn't guaranteed).
  390.  
  391.  
  392.  
  393.      Page 6                        (printed 10/23/98)
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  401.  
  402.  
  403.  
  404.       FFFFEEEETTTTCCCCHHHHIIIINNNNGGGG TTTTHHHHEEEE VVVVAAAALLLLUUUUEEEE OOOORRRR    VVVVAAAALLLLUUUUEEEESSSS OOOOFFFF AAAA SSSSIIIINNNNGGGGLLLLEEEE NNNNAAAAMMMMEEEEDDDD PPPPAAAARRRRAAAAMMMMEEEETTTTEEEERRRR::::
  405.  
  406.           @values =    $query->param('foo');
  407.  
  408.             -or-
  409.  
  410.           $value = $query->param('foo');
  411.  
  412.       Pass the _p_a_r_a_m() method a single argument to fetch the value
  413.       of the named parameter. If the parameter is multivalued
  414.       (e.g.    from multiple selections in a scrolling    list), you can
  415.       ask to receive an array.  Otherwise the method will return a
  416.       single value.
  417.  
  418.       SSSSEEEETTTTTTTTIIIINNNNGGGG TTTTHHHHEEEE _V_A_L_U_E(S) OF A NAMED PARAMETER:
  419.  
  420.           $query->param('foo','an','array','of','values');
  421.  
  422.       This sets the    value for the named parameter 'foo' to an
  423.       array    of values.  This is one    way to change the value    of a
  424.       field    AFTER the script has been invoked once before.
  425.       (Another way is with the -override parameter accepted    by all
  426.       methods that generate    form elements.)
  427.  
  428.       _p_a_r_a_m() also recognizes a named parameter style of calling
  429.       described in more detail later:
  430.  
  431.           $query->param(-name=>'foo',-values=>['an','array','of','values']);
  432.  
  433.                     -or-
  434.  
  435.           $query->param(-name=>'foo',-value=>'the value');
  436.  
  437.  
  438.       AAAAPPPPPPPPEEEENNNNDDDDIIIINNNNGGGG AAAADDDDDDDDIIIITTTTIIIIOOOONNNNAAAALLLL VVVVAAAALLLLUUUUEEEESSSS TTTTOOOO AAAA NNNNAAAAMMMMEEEEDDDD PPPPAAAARRRRAAAAMMMMEEEETTTTEEEERRRR::::
  439.  
  440.          $query->append(-name=>'foo',-values=>['yet','more','values']);
  441.  
  442.       This adds a value or list of values to the named parameter.
  443.       The values are appended to the end of    the parameter if it
  444.       already exists.  Otherwise the parameter is created.    Note
  445.       that this method only    recognizes the named argument calling
  446.       syntax.
  447.  
  448.       IIIIMMMMPPPPOOOORRRRTTTTIIIINNNNGGGG AAAALLLLLLLL    PPPPAAAARRRRAAAAMMMMEEEETTTTEEEERRRRSSSS IIIINNNNTTTTOOOO    AAAA NNNNAAAAMMMMEEEESSSSPPPPAAAACCCCEEEE::::
  449.  
  450.          $query->import_names('R');
  451.  
  452.       This creates a series    of variables in    the 'R'    namespace.
  453.       For example, $R::foo,    @R:foo.     For keyword lists, a variable
  454.       @R::keywords will appear.  If    no namespace is    given, this
  455.       method will assume 'Q'.  WARNING:  don't import anything
  456.  
  457.  
  458.  
  459.      Page 7                        (printed 10/23/98)
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  467.  
  468.  
  469.  
  470.       into risk!!!!
  471.  
  472.       In older versions, this method was called iiiimmmmppppoooorrrrtttt(((()))).  As of
  473.       version 2.20,    this name has been removed completely to avoid
  474.       conflict with    the built-in Perl module iiiimmmmppppoooorrrrtttt    operator.
  475.  
  476.       DDDDEEEELLLLEEEETTTTIIIINNNNGGGG AAAA PPPPAAAARRRRAAAAMMMMEEEETTTTEEEERRRR CCCCOOOOMMMMPPPPLLLLEEEETTTTEEEELLLLYYYY::::
  477.  
  478.           $query->delete('foo');
  479.  
  480.       This completely clears a parameter.  It sometimes useful for
  481.       resetting parameters that you    don't want passed down between
  482.       script invocations.
  483.  
  484.       If you are using the function    call interface,    use "_D_e_l_e_t_e()"
  485.       instead to avoid conflicts with Perl's built-in delete
  486.       operator.
  487.  
  488.       DDDDEEEELLLLEEEETTTTIIIINNNNGGGG AAAALLLLLLLL PPPPAAAARRRRAAAAMMMMEEEETTTTEEEERRRRSSSS::::
  489.  
  490.          $query->delete_all();
  491.  
  492.       This clears the CGI object completely.  It might be useful
  493.       to ensure that all the defaults are taken when you create a
  494.       fill-out form.
  495.  
  496.       Use _D_e_l_e_t_e__a_l_l() instead if you are using the    function call
  497.       interface.
  498.  
  499.       DDDDIIIIRRRREEEECCCCTTTT AAAACCCCCCCCEEEESSSSSSSS    TTTTOOOO TTTTHHHHEEEE PPPPAAAARRRRAAAAMMMMEEEETTTTEEEERRRR LLLLIIIISSSSTTTT::::
  500.  
  501.          $q->param_fetch('address')->[1] = '1313 Mockingbird Lane';
  502.          unshift @{$q->param_fetch(-name=>'address')},'George Munster';
  503.  
  504.       If you need access to    the parameter list in a    way that isn't
  505.       covered by the methods above,    you can    obtain a direct
  506.       reference to it by calling the ppppaaaarrrraaaammmm____ffffeeeettttcccchhhh(((()))) method with the
  507.       name of the .     This will return an array reference to    the
  508.       named    parameters, which you then can manipulate in any way
  509.       you like.
  510.  
  511.       You can also use a named argument style using    the ----nnnnaaaammmmeeee
  512.       argument.
  513.  
  514.       SSSSAAAAVVVVIIIINNNNGGGG TTTTHHHHEEEE SSSSTTTTAAAATTTTEEEE OOOOFFFF TTTTHHHHEEEE SSSSCCCCRRRRIIIIPPPPTTTT TTTTOOOO AAAA FFFFIIIILLLLEEEE::::
  515.  
  516.           $query->save(FILEHANDLE)
  517.  
  518.       This will write the current state of the form    to the
  519.       provided filehandle.    You can    read it    back in    by providing a
  520.       filehandle to    the _n_e_w() method.  Note    that the filehandle
  521.       can be a file, a pipe, or whatever!
  522.  
  523.  
  524.  
  525.      Page 8                        (printed 10/23/98)
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  533.  
  534.  
  535.  
  536.       The format of    the saved file is:
  537.  
  538.           NAME1=VALUE1
  539.           NAME1=VALUE1'
  540.           NAME2=VALUE2
  541.           NAME3=VALUE3
  542.           =
  543.  
  544.       Both name and    value are URL escaped.    Multi-valued CGI
  545.       parameters are represented as    repeated names.     A session
  546.       record is delimited by a single = symbol.  You can write out
  547.       multiple records and read them back in with several calls to
  548.       nnnneeeewwww.    You can    do this    across several sessions    by opening the
  549.       file in append mode, allowing    you to create primitive    guest
  550.       books, or to keep a history of users'    queries.  Here's a
  551.       short    example    of creating multiple session records:
  552.  
  553.          use CGI;
  554.  
  555.          open (OUT,">>test.out") ||    die;
  556.          $records =    5;
  557.          foreach (0..$records) {
  558.          my $q = new CGI;
  559.          $q->param(-name=>'counter',-value=>$_);
  560.          $q->save(OUT);
  561.          }
  562.          close OUT;
  563.  
  564.          # reopen for reading
  565.          open (IN,"test.out") || die;
  566.          while (!eof(IN)) {
  567.          my $q = new CGI(IN);
  568.          print $q->param('counter'),"\n";
  569.          }
  570.  
  571.       The file format used for save/restore    is identical to    that
  572.       used by the Whitehead    Genome Center's    data exchange format
  573.       "Boulderio", and can be manipulated and even databased using
  574.       Boulderio utilities.    See
  575.         http://www.genome.wi.mit.edu/genome_software/other/boulder.html
  576.  
  577.       for further details.
  578.  
  579.       If you wish to use this method from the function-oriented
  580.       (non-OO) interface, the exported name    for this method    is
  581.       ssssaaaavvvveeee____ppppaaaarrrraaaammmmeeeetttteeeerrrrssss(((()))).
  582.  
  583.       UUUUSSSSIIIINNNNGGGG    TTTTHHHHEEEE FFFFUUUUNNNNCCCCTTTTIIIIOOOONNNN----OOOORRRRIIIIEEEENNNNTTTTEEEEDDDD IIIINNNNTTTTEEEERRRRFFFFAAAACCCCEEEE
  584.  
  585.       To use the function-oriented interface, you must specify
  586.       which    CGI.pm routines    or sets    of routines to import into
  587.       your script's    namespace.  There is a small overhead
  588.  
  589.  
  590.  
  591.      Page 9                        (printed 10/23/98)
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  599.  
  600.  
  601.  
  602.       associated with this importation, but    it isn't much.
  603.  
  604.          use CGI <list of methods>;
  605.  
  606.       The listed methods will be imported into the current
  607.       package; you can call    them directly without creating a CGI
  608.       object first.     This example shows how    to import the ppppaaaarrrraaaammmm(((())))
  609.       and hhhheeeeaaaaddddeeeerrrr(((()))) methods,    and then use them directly:
  610.  
  611.          use CGI 'param','header';
  612.          print header('text/plain');
  613.          $zipcode =    param('zipcode');
  614.  
  615.       More frequently, you'll import common    sets of    functions by
  616.       referring to the gropus by name.  All    function sets are
  617.       preceded with    a ":"  character as in ":html3"    (for tags
  618.       defined in the HTML 3    standard).
  619.  
  620.       Here is a list of the    function sets you can import:
  621.  
  622.       ::::ccccggggiiii
  623.           Import all CGI-handling methods, such as ppppaaaarrrraaaammmm(((()))),
  624.           ppppaaaatttthhhh____iiiinnnnffffoooo(((()))) and the like.
  625.  
  626.       ::::ffffoooorrrrmmmm
  627.           Import all fill-out form generating methods, such    as
  628.           tttteeeexxxxttttffffiiiieeeelllldddd(((()))).
  629.  
  630.       ::::hhhhttttmmmmllll2222
  631.           Import all methods that generate HTML 2.0    standard
  632.           elements.
  633.  
  634.       ::::hhhhttttmmmmllll3333
  635.           Import all methods that generate HTML 3.0    proposed
  636.           elements (such as    <table>, <super> and <sub>).
  637.  
  638.       ::::nnnneeeettttssssccccaaaappppeeee
  639.           Import all methods that generate Netscape-specific HTML
  640.           extensions.
  641.  
  642.       ::::hhhhttttmmmmllll
  643.           Import all HTML-generating shortcuts (i.e. 'html2' +
  644.           'html3' +    'netscape')...
  645.  
  646.       ::::ssssttttaaaannnnddddaaaarrrrdddd
  647.           Import "standard"    features, 'html2', 'html3', 'form' and
  648.           'cgi'.
  649.  
  650.       ::::aaaallllllll
  651.           Import all the available methods.     For the full list,
  652.           see the CGI.pm code, where the variable %TAGS is
  653.           defined.
  654.  
  655.  
  656.  
  657.      Page 10                        (printed 10/23/98)
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  665.  
  666.  
  667.  
  668.       If you import    a function name    that is    not part of CGI.pm,
  669.       the module will treat    it as a    new HTML tag and generate the
  670.       appropriate subroutine.  You can then    use it like any    other
  671.       HTML tag.  This is to    provide    for the    rapidly-evolving HTML
  672.       "standard."  For example, say    Microsoft comes    out with a new
  673.       tag called <GRADIENT>    (which causes the user's desktop to be
  674.       flooded with a rotating gradient fill    until his machine
  675.       reboots).  You don't need to wait for    a new version of
  676.       CGI.pm to start using    it immeidately:
  677.  
  678.          use CGI qw/:standard :html3 gradient/;
  679.          print gradient({-start=>'red',-end=>'blue'});
  680.  
  681.       Note that in the interests of    execution speed    CGI.pm does
  682.       nnnnooootttt use the standard the _E_x_p_o_r_t_e_r manpage syntax for
  683.       specifying load symbols.  This may change in the future.
  684.  
  685.       If you import    any of the state-maintaining CGI or form-
  686.       generating methods, a    default    CGI object will    be created and
  687.       initialized automatically the    first time you use any of the
  688.       methods that require one to be present.  This    includes
  689.       ppppaaaarrrraaaammmm(((()))), tttteeeexxxxttttffffiiiieeeelllldddd(((()))),    ssssuuuubbbbmmmmiiiitttt(((()))) and the like.    (If you    need
  690.       direct access    to the CGI object, you can find    it in the
  691.       global variable $$$$CCCCGGGGIIII::::::::QQQQ).  By    importing CGI.pm methods, you
  692.       can create visually elegant scripts:
  693.  
  694.          use CGI qw/:standard/;
  695.          print
  696.          header,
  697.          start_html('Simple Script'),
  698.          h1('Simple Script'),
  699.          start_form,
  700.          "What's your name? ",textfield('name'),p,
  701.          "What's the combination?",
  702.          checkbox_group(-name=>'words',
  703.                 -values=>['eenie','meenie','minie','moe'],
  704.                 -defaults=>['eenie','moe']),p,
  705.          "What's your favorite color?",
  706.          popup_menu(-name=>'color',
  707.                 -values=>['red','green','blue','chartreuse']),p,
  708.          submit,
  709.          end_form,
  710.          hr,"\n";
  711.  
  712.           if (param) {
  713.          print
  714.              "Your name    is ",em(param('name')),p,
  715.              "The keywords are:    ",em(join(", ",param('words'))),p,
  716.              "Your favorite color is ",em(param('color')),".\n";
  717.           }
  718.           print end_html;
  719.  
  720.  
  721.  
  722.  
  723.      Page 11                        (printed 10/23/98)
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  731.  
  732.  
  733.  
  734.       PPPPRRRRAAAAGGGGMMMMAAAASSSS
  735.  
  736.       In addition to the function sets, there are a    number of
  737.       pragmas that you can import.    Pragmas, which are always
  738.       preceded by a    hyphen,    change the way that CGI.pm functions
  739.       in various ways.  Pragmas, function sets, and    individual
  740.       functions can    all be imported    in the same _u_s_e() line.     For
  741.       example, the following use statement imports the standard
  742.       set of functions and disables    debugging mode (pragma
  743.       -no_debug):
  744.  
  745.          use CGI qw/:standard -no_debug/;
  746.  
  747.       The current list of pragmas is as follows:
  748.  
  749.       -any
  750.           When you _u_s_e _C_G_I -_a_n_y, then any method that the query
  751.           object doesn't recognize will be interpreted as a    new
  752.           HTML tag.     This allows you to support the    next _a_d    _h_o_c
  753.           Netscape or Microsoft HTML extension.  This lets you go
  754.           wild with    new and    unsupported tags:
  755.  
  756.          use CGI qw(-any);
  757.          $q=new    CGI;
  758.          print $q->gradient({speed=>'fast',start=>'red',end=>'blue'});
  759.  
  760.           Since using <cite>any</cite> causes any mistyped method
  761.           name to be interpreted as    an HTML    tag, use it with care
  762.           or not at    all.
  763.  
  764.       -compile
  765.           This causes the indicated    autoloaded methods to be
  766.           compiled up front, rather    than deferred to later.     This
  767.           is useful    for scripts that run for an extended period of
  768.           time under FastCGI or mod_perl, and for those destined
  769.           to be crunched by    Malcom Beattie's Perl compiler.     Use
  770.           it in conjunction    with the methods or method familes you
  771.           plan to use.
  772.  
  773.          use CGI qw(-compile :standard :html3);
  774.  
  775.           or even
  776.  
  777.          use CGI qw(-compile :all);
  778.  
  779.           Note that    using the -compile pragma in this way will
  780.           always have the effect of    importing the compiled
  781.           functions    into the current namespace.  If    you want to
  782.           compile without importing    use the    _c_o_m_p_i_l_e() method
  783.           instead (see below).
  784.  
  785.  
  786.  
  787.  
  788.  
  789.      Page 12                        (printed 10/23/98)
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  797.  
  798.  
  799.  
  800.       -nph
  801.           This makes CGI.pm    produce    a header appropriate for an
  802.           NPH (no parsed header) script.  You may need to do other
  803.           things as    well to    tell the server    that the script    is
  804.           NPH.  See    the discussion of NPH scripts below.
  805.  
  806.       -autoload
  807.           This overrides the autoloader so that any    function in
  808.           your program that    is not recognized is referred to
  809.           CGI.pm for possible evaluation.  This allows you to use
  810.           all the CGI.pm functions without adding them to your
  811.           symbol table, which is of    concern    for mod_perl users who
  812.           are worried about    memory consumption.  _W_a_r_n_i_n_g: when
  813.           -_a_u_t_o_l_o_a_d    is in effect, you cannot use "poetry mode"
  814.           (functions without the parenthesis).  Use    _h_r() rather
  815.           than _h_r, or add something    like _u_s_e _s_u_b_s _q_w/_h_r _p _h_e_a_d_e_r/
  816.           to the top of your script.
  817.  
  818.       -no_debug
  819.           This turns off the command-line processing features.  If
  820.           you want to run a    CGI.pm script from the command line to
  821.           produce HTML, and    you don't want it pausing to request
  822.           CGI parameters from standard input or the    command    line,
  823.           then use this pragma:
  824.  
  825.          use CGI qw(-no_debug :standard);
  826.  
  827.           If you'd like to process the command-line    parameters but
  828.           not standard input, this should work:
  829.  
  830.          use CGI qw(-no_debug :standard);
  831.          restore_parameters(join('&',@ARGV));
  832.  
  833.           See the section on debugging for more details.
  834.  
  835.  
  836.       -private_tempfiles
  837.           CGI.pm can process uploaded file.    Ordinarily it spools
  838.           the uploaded file    to a temporary directory, then deletes
  839.           the file when done.  However, this opens the risk    of
  840.           eavesdropping as described in the    file upload section.
  841.           Another CGI script author    could peek at this data    during
  842.           the upload, even if it is    confidential information. On
  843.           Unix systems, the    -private_tempfiles pragma will cause
  844.           the temporary file to be unlinked    as soon    as it is
  845.           opened and before    any data is written into it,
  846.           eliminating the risk of eavesdropping.  n    =back
  847.  
  848.      GGGGEEEENNNNEEEERRRRAAAATTTTIIIINNNNGGGG    DDDDYYYYNNNNAAAAMMMMIIIICCCC    DDDDOOOOCCCCUUUUMMMMEEEENNNNTTTTSSSS
  849.       Most of CGI.pm's functions deal with creating    documents on
  850.       the fly.  Generally you will produce the HTTP    header first,
  851.       followed by the document itself.  CGI.pm provides functions
  852.  
  853.  
  854.  
  855.      Page 13                        (printed 10/23/98)
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  863.  
  864.  
  865.  
  866.       for generating HTTP headers of various types as well as for
  867.       generating HTML.  For    creating GIF images, see the GD.pm
  868.       module.
  869.  
  870.       Each of these    functions produces a fragment of HTML or HTTP
  871.       which    you can    print out directly so that it displays in the
  872.       browser window, append to a string, or save to a file    for
  873.       later    use.
  874.  
  875.       CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA SSSSTTTTAAAANNNNDDDDAAAARRRRDDDD HHHHTTTTTTTTPPPP HHHHEEEEAAAADDDDEEEERRRR::::
  876.  
  877.       Normally the first thing you will do in any CGI script is
  878.       print    out an HTTP header.  This tells    the browser what type
  879.       of document to expect, and gives other optional information,
  880.       such as the language,    expiration date, and whether to    cache
  881.       the document.     The header can    also be    manipulated for
  882.       special purposes, such as server push    and pay    per view
  883.       pages.
  884.  
  885.           print    $query->header;
  886.  
  887.                -or-
  888.  
  889.           print    $query->header('image/gif');
  890.  
  891.                -or-
  892.  
  893.           print    $query->header('text/html','204    No response');
  894.  
  895.                -or-
  896.  
  897.           print    $query->header(-type=>'image/gif',
  898.                        -nph=>1,
  899.                        -status=>'402 Payment required',
  900.                        -expires=>'+3d',
  901.                        -cookie=>$cookie,
  902.                        -Cost=>'$2.00');
  903.  
  904.       _h_e_a_d_e_r() returns the Content-type: header.  You can provide
  905.       your own MIME    type if    you choose, otherwise it defaults to
  906.       text/html.  An optional second parameter specifies the
  907.       status code and a human-readable message.  For example, you
  908.       can specify 204, "No response" to create a script that tells
  909.       the browser to do nothing at all.
  910.  
  911.       The last example shows the named argument style for passing
  912.       arguments to the CGI methods using named parameters.
  913.       Recognized parameters    are ----ttttyyyyppppeeee, ----ssssttttaaaattttuuuussss, ----eeeexxxxppppiiiirrrreeeessss, and
  914.       ----ccccooooooookkkkiiiieeee.  Any    other named parameters will be stripped    of
  915.       their    initial    hyphens    and turned into    header fields,
  916.       allowing you to specify any HTTP header you desire.
  917.       Internal underscores will be turned into hyphens:
  918.  
  919.  
  920.  
  921.      Page 14                        (printed 10/23/98)
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  929.  
  930.  
  931.  
  932.           print $query->header(-Content_length=>3002);
  933.  
  934.       Most browsers    will not cache the output from CGI scripts.
  935.       Every    time the browser reloads the page, the script is
  936.       invoked anew.     You can change    this behavior with the
  937.       ----eeeexxxxppppiiiirrrreeeessss parameter.  When you    specify    an absolute or
  938.       relative expiration interval with this parameter, some
  939.       browsers and proxy servers will cache    the script's output
  940.       until    the indicated expiration date.    The following forms
  941.       are all valid    for the    -expires field:
  942.  
  943.           +30s                    30 seconds from now
  944.           +10m                    ten    minutes    from now
  945.           +1h                    one    hour from now
  946.           -1d                    yesterday (i.e. "ASAP!")
  947.           now                    immediately
  948.           +3M                    in three months
  949.           +10y                    in ten years time
  950.           Thursday, 25-Apr-1999    00:40:33 GMT  at the indicated time & date
  951.  
  952.       The ----ccccooooooookkkkiiiieeee parameter    generates a header that    tells the
  953.       browser to provide a "magic cookie" during all subsequent
  954.       transactions with your script.  Netscape cookies have    a
  955.       special format that includes interesting attributes such as
  956.       expiration time.  Use    the _c_o_o_k_i_e() method to create and
  957.       retrieve session cookies.
  958.  
  959.       The ----nnnnpppphhhh parameter, if set to    a true value, will issue the
  960.       correct headers to work with a NPH (no-parse-header) script.
  961.       This is important to use with    certain    servers, such as
  962.       Microsoft Internet Explorer, which expect all    their scripts
  963.       to be    NPH.
  964.  
  965.       GGGGEEEENNNNEEEERRRRAAAATTTTIIIINNNNGGGG AAAA RRRREEEEDDDDIIIIRRRREEEECCCCTTTTIIIIOOOONNNN HHHHEEEEAAAADDDDEEEERRRR
  966.  
  967.          print $query->redirect('http://somewhere.else/in/movie/land');
  968.  
  969.       Sometimes you    don't want to produce a    document yourself, but
  970.       simply redirect the browser elsewhere, perhaps choosing a
  971.       URL based on the time    of day or the identity of the user.
  972.  
  973.       The _r_e_d_i_r_e_c_t() function redirects the    browser    to a different
  974.       URL.    If you use redirection like this, you should nnnnooootttt print
  975.       out a    header as well.     As of version 2.0, we produce both
  976.       the unofficial Location:  header and the official URI:
  977.       header.  This    should satisfy most servers and    browsers.
  978.  
  979.       One hint I can offer is that relative    links may not work
  980.       correctly when you generate a    redirection to another
  981.       document on your site.  This is due to a well-intentioned
  982.       optimization that some servers use.  The solution to this is
  983.       to use the full URL (including the http: part) of the
  984.  
  985.  
  986.  
  987.      Page 15                        (printed 10/23/98)
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  995.  
  996.  
  997.  
  998.       document you are redirecting to.
  999.  
  1000.       You can also use named arguments:
  1001.  
  1002.           print $query->redirect(-uri=>'http://somewhere.else/in/movie/land',
  1003.                      -nph=>1);
  1004.  
  1005.       The ----nnnnpppphhhh parameter, if set to    a true value, will issue the
  1006.       correct headers to work with a NPH (no-parse-header) script.
  1007.       This is important to use with    certain    servers, such as
  1008.       Microsoft Internet Explorer, which expect all    their scripts
  1009.       to be    NPH.
  1010.  
  1011.       CCCCRRRREEEEAAAATTTTIIIINNNNGGGG TTTTHHHHEEEE HHHHTTTTMMMMLLLL DDDDOOOOCCCCUUUUMMMMEEEENNNNTTTT HHHHEEEEAAAADDDDEEEERRRR
  1012.  
  1013.          print $query->start_html(-title=>'Secrets of the Pyramids',
  1014.                       -author=>'fred@capricorn.org',
  1015.                       -base=>'true',
  1016.                       -target=>'_blank',
  1017.                       -meta=>{'keywords'=>'pharaoh secret mummy',
  1018.                           'copyright'=>'copyright 1996 King    Tut'},
  1019.                       -style=>{'src'=>'/styles/style1.css'},
  1020.                       -BGCOLOR=>'blue');
  1021.  
  1022.       After    creating the HTTP header, most CGI scripts will    start
  1023.       writing out an HTML document.     The _s_t_a_r_t__h_t_m_l() routine
  1024.       creates the top of the page, along with a lot    of optional
  1025.       information that controls the    page's appearance and
  1026.       behavior.
  1027.  
  1028.       This method returns a    canned HTML header and the opening
  1029.       <BODY> tag.  All parameters are optional.  In    the named
  1030.       parameter form, recognized parameters    are -title, -author,
  1031.       -base, -xbase    and -target (see below for the explanation).
  1032.       Any additional parameters you    provide, such as the Netscape
  1033.       unofficial BGCOLOR attribute,    are added to the <BODY>    tag.
  1034.       Additional parameters    must be    proceeded by a hyphen.
  1035.  
  1036.       The argument ----xxxxbbbbaaaasssseeee allows you to provide an HREF for    the
  1037.       <BASE> tag different from the    current    location, as in
  1038.  
  1039.           -xbase=>"http://home.mcom.com/"
  1040.  
  1041.       All relative links will be interpreted relative to this tag.
  1042.  
  1043.       The argument ----ttttaaaarrrrggggeeeetttt allows you to provide a default target
  1044.       frame    for all    the links and fill-out forms on    the page.  See
  1045.       the Netscape documentation on    frames for details of how to
  1046.       manipulate this.
  1047.  
  1048.           -target=>"answer_window"
  1049.  
  1050.  
  1051.  
  1052.  
  1053.      Page 16                        (printed 10/23/98)
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  1061.  
  1062.  
  1063.  
  1064.       All relative links will be interpreted relative to this tag.
  1065.       You add arbitrary meta information to    the header with    the
  1066.       ----mmmmeeeettttaaaa    argument.  This    argument expects a reference to    an
  1067.       associative array containing name/value pairs    of meta
  1068.       information.    These will be turned into a series of header
  1069.       <META> tags that look    something like this:
  1070.  
  1071.           <META NAME="keywords" CONTENT="pharaoh secret mummy">
  1072.           <META NAME="description" CONTENT="copyright 1996 King Tut">
  1073.  
  1074.       There    is no support for the HTTP-EQUIV type of <META>    tag.
  1075.       This is because you can modify the HTTP header directly with
  1076.       the hhhheeeeaaaaddddeeeerrrr(((()))) method.    For example, if    you want to send the
  1077.       Refresh: header, do it in the    _h_e_a_d_e_r() method:
  1078.  
  1079.           print $q->header(-Refresh=>'10; URL=http://www.capricorn.com');
  1080.  
  1081.       The ----ssssttttyyyylllleeee tag is used to incorporate    cascading stylesheets
  1082.       into your code.  See the section on CASCADING    STYLESHEETS
  1083.       for more information.
  1084.  
  1085.       You can place    other arbitrary    HTML elements to the <HEAD>
  1086.       section with the ----hhhheeeeaaaadddd tag.  For example, to place the
  1087.       rarely-used <LINK> element in    the head section, use this:
  1088.  
  1089.           print $q->start_html(-head=>Link({-rel=>'next',
  1090.                         -href=>'http://www.capricorn.com/s2.html'}));
  1091.  
  1092.       To incorporate multiple HTML elements    into the <HEAD>
  1093.       section, just    pass an    array reference:
  1094.  
  1095.           print $q->start_html(-head=>[
  1096.                     Link({-rel=>'next',
  1097.                           -href=>'http://www.capricorn.com/s2.html'}),
  1098.                     Link({-rel=>'previous',
  1099.                           -href=>'http://www.capricorn.com/s1.html'})
  1100.                        ]
  1101.                    );
  1102.  
  1103.       JAVASCRIPTING: The ----ssssccccrrrriiiipppptttt, ----nnnnooooSSSSccccrrrriiiipppptttt, ----oooonnnnLLLLooooaaaadddd,
  1104.       ----oooonnnnMMMMoooouuuusssseeeeOOOOvvvveeeerrrr,    ----oooonnnnMMMMoooouuuusssseeeeOOOOuuuutttt and    ----oooonnnnUUUUnnnnllllooooaaaadddd parameters are used
  1105.       to add Netscape JavaScript calls to your pages.  ----ssssccccrrrriiiipppptttt
  1106.       should point to a block of text containing JavaScript
  1107.       function definitions.     This block will be placed within a
  1108.       <SCRIPT> block inside    the HTML (not HTTP) header.  The block
  1109.       is placed in the header in order to give your    page a
  1110.       fighting chance of having all    its JavaScript functions in
  1111.       place    even if    the user presses the stop button before    the
  1112.       page has loaded completely.  CGI.pm attempts to format the
  1113.       script in such a way that JavaScript-naive browsers will not
  1114.       choke    on the code: unfortunately there are some browsers,
  1115.       such as Chimera for Unix, that get confused by it
  1116.  
  1117.  
  1118.  
  1119.      Page 17                        (printed 10/23/98)
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  1127.  
  1128.  
  1129.  
  1130.       nevertheless.
  1131.  
  1132.       The ----oooonnnnLLLLooooaaaadddd and ----oooonnnnUUUUnnnnllllooooaaaadddd parameters point to    fragments of
  1133.       JavaScript code to execute when the page is respectively
  1134.       opened and closed by the browser.  Usually these parameters
  1135.       are calls to functions defined in the    ----ssssccccrrrriiiipppptttt    field:
  1136.  
  1137.         $query = new CGI;
  1138.         print $query->header;
  1139.         $JSCRIPT=<<END;
  1140.         // Ask a silly question
  1141.         function riddle_me_this() {
  1142.            var r = prompt("What    walks on four legs in the morning, " +
  1143.                  "two legs in the afternoon, " +
  1144.                  "and three legs in the    evening?");
  1145.            response(r);
  1146.         }
  1147.         // Get a silly answer
  1148.         function response(answer) {
  1149.            if (answer == "man")
  1150.               alert("Right you are!");
  1151.            else
  1152.               alert("Wrong!  Guess again.");
  1153.         }
  1154.         END
  1155.         print $query->start_html(-title=>'The Riddle of    the Sphinx',
  1156.                      -script=>$JSCRIPT);
  1157.  
  1158.       Use the ----nnnnooooSSSSccccrrrriiiipppptttt parameter to pass some HTML    text that will
  1159.       be displayed on browsers that    do not have JavaScript (or
  1160.       browsers where JavaScript is turned off).
  1161.  
  1162.       Netscape 3.0 recognizes several attributes of    the <SCRIPT>
  1163.       tag, including LANGUAGE and SRC.  The    latter is particularly
  1164.       interesting, as it allows you    to keep    the JavaScript code in
  1165.       a file or CGI    script rather than cluttering up each page
  1166.       with the source.  To use these attributes pass a HASH
  1167.       reference in the ----ssssccccrrrriiiipppptttt parameter containing    one or more of
  1168.       -language, -src, or -code:
  1169.  
  1170.           print $q->start_html(-title=>'The    Riddle of the Sphinx',
  1171.                    -script=>{-language=>'JAVASCRIPT',
  1172.                          -src=>'/javascript/sphinx.js'}
  1173.                    );
  1174.  
  1175.           print $q->(-title=>'The Riddle of    the Sphinx',
  1176.              -script=>{-language=>'PERLSCRIPT'},
  1177.                    -code=>'print "hello    world!\n;"'
  1178.              );
  1179.  
  1180.       A final feature allows you to    incorporate multiple <SCRIPT>
  1181.       sections into    the header.  Just pass the list    of script
  1182.  
  1183.  
  1184.  
  1185.      Page 18                        (printed 10/23/98)
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  1193.  
  1194.  
  1195.  
  1196.       sections as an array reference.  this    allows you to specify
  1197.       different source files for different dialects    of JavaScript.
  1198.       Example:
  1199.  
  1200.            print $q->start_html(-title=>'The Riddle of the Sphinx',
  1201.                     -script=>[
  1202.                           {    -language =>    'JavaScript1.0',
  1203.                         -src      =>    '/javascript/utilities10.js'
  1204.                           },
  1205.                           {    -language =>    'JavaScript1.1',
  1206.                         -src      =>    '/javascript/utilities11.js'
  1207.                           },
  1208.                           {    -language =>    'JavaScript1.2',
  1209.                         -src      =>    '/javascript/utilities12.js'
  1210.                           },
  1211.                           {    -language =>    'JavaScript28.2',
  1212.                         -src      =>    '/javascript/utilities219.js'
  1213.                           }
  1214.                        ]
  1215.                        );
  1216.            </pre>
  1217.  
  1218.       If this looks    a bit extreme, take my advice and stick    with
  1219.       straight CGI scripting.
  1220.  
  1221.       See
  1222.  
  1223.          http://home.netscape.com/eng/mozilla/2.0/handbook/javascript/
  1224.  
  1225.       for more information about JavaScript.
  1226.  
  1227.       The old-style    positional parameters are as follows:
  1228.  
  1229.       PPPPaaaarrrraaaammmmeeeetttteeeerrrrssss::::
  1230.  
  1231.       1.      The title
  1232.  
  1233.       2.      The author's e-mail address (will create a <LINK
  1234.           REV="MADE"> tag if present
  1235.  
  1236.       3.      A 'true' flag    if you want to include a <BASE>    tag in
  1237.           the header.  This helps resolve relative addresses
  1238.           to absolute ones when    the document is    moved, but
  1239.           makes    the document hierarchy non-portable.  Use with
  1240.           care!
  1241.  
  1242.       4, 5,    6...
  1243.           Any other parameters you want    to include in the
  1244.           <BODY> tag.  This is a good place to put Netscape
  1245.           extensions, such as colors and wallpaper patterns.
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.      Page 19                        (printed 10/23/98)
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  1259.  
  1260.  
  1261.  
  1262.       EEEENNNNDDDDIIIINNNNGGGG TTTTHHHHEEEE HHHHTTTTMMMMLLLL DDDDOOOOCCCCUUUUMMMMEEEENNNNTTTT::::
  1263.  
  1264.           print    $query->end_html
  1265.  
  1266.       This ends an HTML document by    printing the </BODY></HTML>
  1267.       tags.
  1268.  
  1269.       CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA SSSSEEEELLLLFFFF----RRRREEEEFFFFEEEERRRREEEENNNNCCCCIIIINNNNGGGG UUUURRRRLLLL TTTTHHHHAAAATTTT PPPPRRRREEEESSSSEEEERRRRVVVVEEEESSSS SSSSTTTTAAAATTTTEEEE
  1270.       IIIINNNNFFFFOOOORRRRMMMMAAAATTTTIIIIOOOONNNN::::
  1271.  
  1272.           $myself =    $query->self_url;
  1273.           print "<A    HREF=$myself>I'm talking to myself.</A>";
  1274.  
  1275.       _s_e_l_f__u_r_l() will return a URL,    that, when selected, will
  1276.       reinvoke this    script with all    its state information intact.
  1277.       This is most useful when you want to jump around within the
  1278.       document using internal anchors but you don't    want to
  1279.       disrupt the current contents of the _f_o_r_m(s).    Something like
  1280.       this will do the trick.
  1281.  
  1282.            $myself = $query->self_url;
  1283.            print "<A HREF=$myself#table1>See table 1</A>";
  1284.            print "<A HREF=$myself#table2>See table 2</A>";
  1285.            print "<A HREF=$myself#yourself>See for yourself</A>";
  1286.  
  1287.       If you want more control over    what's returned, using the
  1288.       uuuurrrrllll(((())))    method instead.
  1289.  
  1290.       You can also retrieve    the unprocessed    query string with
  1291.       _q_u_e_r_y__s_t_r_i_n_g():
  1292.  
  1293.           $the_string = $query->query_string;
  1294.  
  1295.  
  1296.       OOOOBBBBTTTTAAAAIIIINNNNIIIINNNNGGGG TTTTHHHHEEEE    SSSSCCCCRRRRIIIIPPPPTTTT''''SSSS UUUURRRRLLLL
  1297.  
  1298.           $full_url         = $query->url();
  1299.           $full_url         = $query->url(-full=>1);  #alternative syntax
  1300.           $relative_url  = $query->url(-relative=>1);
  1301.           $absolute_url  = $query->url(-absolute=>1);
  1302.           $url_with_path = $query->url(-path_info=>1);
  1303.           $url_with_path_and_query = $query->url(-path_info=>1,-query=>1);
  1304.  
  1305.       uuuurrrrllll(((())))    returns    the script's URL in a variety of formats.
  1306.       Called without any arguments,    it returns the full form of
  1307.       the URL, including host name and port    number
  1308.  
  1309.           http://your.host.com/path/to/script.cgi
  1310.  
  1311.       You can modify this format with the following    named
  1312.       arguments:
  1313.  
  1314.  
  1315.  
  1316.  
  1317.      Page 20                        (printed 10/23/98)
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  1325.  
  1326.  
  1327.  
  1328.       ----aaaabbbbssssoooolllluuuutttteeee
  1329.           If true, produce an absolute URL, e.g.
  1330.  
  1331.               /path/to/script.cgi
  1332.  
  1333.  
  1334.       ----rrrreeeellllaaaattttiiiivvvveeee
  1335.           Produce a relative URL.  This    is useful if you want
  1336.           to reinvoke your script with different parameters.
  1337.           For example:
  1338.  
  1339.               script.cgi
  1340.  
  1341.  
  1342.       ----ffffuuuullllllll      Produce the full URL,    exactly    as if called without
  1343.           any arguments.  This overrides the -relative and
  1344.           -absolute arguments.
  1345.  
  1346.       ----ppppaaaatttthhhh    (----ppppaaaatttthhhh____iiiinnnnffffoooo)
  1347.           Append the additional    path information to the    URL.
  1348.           This can be combined with ----ffffuuuullllllll, ----aaaabbbbssssoooolllluuuutttteeee or
  1349.           ----rrrreeeellllaaaattttiiiivvvveeee.  ----ppppaaaatttthhhh____iiiinnnnffffoooo is provided as    a synonym.
  1350.  
  1351.       ----qqqquuuueeeerrrryyyy (----qqqquuuueeeerrrryyyy____ssssttttrrrriiiinnnngggg)
  1352.           Append the query string to the URL.  This can    be
  1353.           combined with    ----ffffuuuullllllll, ----aaaabbbbssssoooolllluuuutttteeee or ----rrrreeeellllaaaattttiiiivvvveeee.
  1354.           ----qqqquuuueeeerrrryyyy____ssssttttrrrriiiinnnngggg    is provided as a synonym.
  1355.  
  1356.      CCCCRRRREEEEAAAATTTTIIIINNNNGGGG SSSSTTTTAAAANNNNDDDDAAAARRRRDDDD HHHHTTTTMMMMLLLL EEEELLLLEEEEMMMMEEEENNNNTTTTSSSS::::
  1357.       CGI.pm defines general HTML shortcut methods for most, if
  1358.       not all of the HTML 3    and HTML 4 tags.  HTML shortcuts are
  1359.       named    after a    single HTML element and    return a fragment of
  1360.       HTML text that you can then print or manipulate as you like.
  1361.       Each shortcut    returns    a fragment of HTML code    that you can
  1362.       append to a string, save to a    file, or, most commonly, print
  1363.       out so that it displays in the browser window.
  1364.  
  1365.       This example shows how to use    the HTML methods:
  1366.  
  1367.          $q    = new CGI;
  1368.          print $q->blockquote(
  1369.                    "Many years ago on the island of",
  1370.                    $q->a({href=>"http://crete.org/"},"Crete"),
  1371.                    "there lived a minotaur named",
  1372.                    $q->strong("Fred."),
  1373.                   ),
  1374.          $q->hr;
  1375.  
  1376.       This results in the following    HTML code (extra newlines have
  1377.       been added for readability):
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383.      Page 21                        (printed 10/23/98)
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  1391.  
  1392.  
  1393.  
  1394.          <blockquote>
  1395.          Many years    ago on the island of
  1396.          <a    HREF="http://crete.org/">Crete</a> there lived
  1397.          a minotaur    named <strong>Fred.</strong>
  1398.          </blockquote>
  1399.          <hr>
  1400.  
  1401.       If you find the syntax for calling the HTML shortcuts
  1402.       awkward, you can import them into your namespace and
  1403.       dispense with    the object syntax completely (see the next
  1404.       section for more details):
  1405.  
  1406.          use CGI ':standard';
  1407.          print blockquote(
  1408.         "Many years ago    on the island of",
  1409.         a({href=>"http://crete.org/"},"Crete"),
  1410.         "there lived a minotaur    named",
  1411.         strong("Fred."),
  1412.         ),
  1413.         hr;
  1414.  
  1415.  
  1416.       PPPPRRRROOOOVVVVIIIIDDDDIIIINNNNGGGG AAAARRRRGGGGUUUUMMMMEEEENNNNTTTTSSSS TTTTOOOO HHHHTTTTMMMMLLLL SSSSHHHHOOOORRRRTTTTCCCCUUUUTTTTSSSS
  1417.  
  1418.       The HTML methods will    accept zero, one or multiple
  1419.       arguments.  If you provide no    arguments, you get a single
  1420.       tag:
  1421.  
  1422.          print hr;      #  <HR>
  1423.  
  1424.       If you provide one or    more string arguments, they are
  1425.       concatenated together    with spaces and    placed between opening
  1426.       and closing tags:
  1427.  
  1428.          print h1("Chapter","1"); #    <H1>Chapter 1</H1>"
  1429.  
  1430.       If the first argument    is an associative array    reference,
  1431.       then the keys    and values of the associative array become the
  1432.       HTML tag's attributes:
  1433.  
  1434.          print a({-href=>'fred.html',-target=>'_new'},
  1435.         "Open a    new frame");
  1436.  
  1437.               <A HREF="fred.html",TARGET="_new">Open a new frame</A>
  1438.  
  1439.       You may dispense with    the dashes in front of the attribute names if
  1440.       you prefer:
  1441.  
  1442.          print img {src=>'fred.gif',align=>'LEFT'};
  1443.  
  1444.              <IMG ALIGN="LEFT" SRC="fred.gif">
  1445.  
  1446.  
  1447.  
  1448.  
  1449.      Page 22                        (printed 10/23/98)
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  1457.  
  1458.  
  1459.  
  1460.       Sometimes an HTML tag    attribute has no argument.  For
  1461.       example, ordered lists can be    marked as COMPACT.  The    syntax
  1462.       for this is an argument that that points to an undef string:
  1463.  
  1464.          print ol({compact=>undef},li('one'),li('two'),li('three'));
  1465.  
  1466.       Prior    to CGI.pm version 2.41,    providing an empty ('')    string
  1467.       as an    attribute argument was the same    as providing undef.
  1468.       However, this    has changed in order to    accomodate those who
  1469.       want to create tags of the form <IMG ALT="">.     The
  1470.       difference is    shown in these two pieces of code:
  1471.  
  1472.          CODE            RESULT
  1473.          _i_m_g({alt=>undef})        <IMG ALT>
  1474.          _i_m_g({alt=>''})        <IMT ALT="">
  1475.  
  1476.       TTTTHHHHEEEE DDDDIIIISSSSTTTTRRRRIIIIBBBBUUUUTTTTIIIIVVVVEEEE PPPPRRRROOOOPPPPEEEERRRRTTTTYYYY OOOOFFFF HHHHTTTTMMMMLLLL SSSSHHHHOOOORRRRTTTTCCCCUUUUTTTTSSSS
  1477.  
  1478.       One of the cool features of the HTML shortcuts is that they
  1479.       are distributive.  If    you give them an argument consisting
  1480.       of a rrrreeeeffffeeeerrrreeeennnncccceeee to a list, the    tag will be distributed    across
  1481.       each element of the list.  For example, here's one way to
  1482.       make an ordered list:
  1483.  
  1484.          print ul(
  1485.                li({-type=>'disc'},['Sneezy','Doc','Sleepy','Happy']);
  1486.              );
  1487.  
  1488.       This example will result in HTML output that looks like
  1489.       this:
  1490.  
  1491.          <UL>
  1492.            <LI TYPE="disc">Sneezy</LI>
  1493.            <LI TYPE="disc">Doc</LI>
  1494.            <LI TYPE="disc">Sleepy</LI>
  1495.            <LI TYPE="disc">Happy</LI>
  1496.          </UL>
  1497.  
  1498.       This is extremely useful for creating    tables.     For example:
  1499.  
  1500.          print table({-border=>undef},
  1501.              caption('When Should You Eat Your Vegetables?'),
  1502.              Tr({-align=>CENTER,-valign=>TOP},
  1503.              [
  1504.             th(['Vegetable', 'Breakfast','Lunch','Dinner']),
  1505.             td(['Tomatoes' , 'no', 'yes', 'yes']),
  1506.             td(['Broccoli' , 'no', 'no',  'yes']),
  1507.             td(['Onions'   , 'yes','yes', 'yes'])
  1508.              ]
  1509.              )
  1510.           );
  1511.  
  1512.  
  1513.  
  1514.  
  1515.      Page 23                        (printed 10/23/98)
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  1523.  
  1524.  
  1525.  
  1526.       HHHHTTTTMMMMLLLL SSSSHHHHOOOORRRRTTTTCCCCUUUUTTTTSSSS AAAANNNNDDDD LLLLIIIISSSSTTTT IIIINNNNTTTTEEEERRRRPPPPOOOOLLLLAAAATTTTIIIIOOOONNNN
  1527.  
  1528.       Consider this    bit of code:
  1529.  
  1530.          print blockquote(em('Hi'),'mom!'));
  1531.  
  1532.       It will ordinarily return the    string that you    probably
  1533.       expect, namely:
  1534.  
  1535.          <BLOCKQUOTE><EM>Hi</EM> mom!</BLOCKQUOTE>
  1536.  
  1537.       Note the space between the element "Hi" and the element
  1538.       "mom!".  CGI.pm puts the extra space there using array
  1539.       interpolation, which is controlled by    the magic $" variable.
  1540.       Sometimes this extra space is    not what you want, for
  1541.       example, when    you are    trying to align    a series of images.
  1542.       In this case,    you can    simply change the value    of $" to an
  1543.       empty    string.
  1544.  
  1545.          {
  1546.         local($") = '';
  1547.         print blockquote(em('Hi'),'mom!'));
  1548.           }
  1549.  
  1550.       I suggest you    put the    code in    a block    as shown here.
  1551.       Otherwise the    change to $" will affect all subsequent    code
  1552.       until    you explicitly reset it.
  1553.  
  1554.       NNNNOOOONNNN----SSSSTTTTAAAANNNNDDDDAAAARRRRDDDD HHHHTTTTMMMMLLLL SSSSHHHHOOOORRRRTTTTCCCCUUUUTTTTSSSS
  1555.  
  1556.       A few    HTML tags don't    follow the standard pattern for
  1557.       various reasons.
  1558.  
  1559.       ccccoooommmmmmmmeeeennnntttt(((()))) generates an HTML comment (<!-- comment -->).
  1560.       Call it like
  1561.  
  1562.           print comment('here is my    comment');
  1563.  
  1564.       Because of conflicts with built-in Perl functions, the
  1565.       following functions begin with initial caps:
  1566.  
  1567.           Select
  1568.           Tr
  1569.           Link
  1570.           Delete
  1571.  
  1572.       In addition, _s_t_a_r_t__h_t_m_l(), _e_n_d__h_t_m_l(), _s_t_a_r_t__f_o_r_m(),
  1573.       _e_n_d__f_o_r_m(), _s_t_a_r_t__m_u_l_t_i_p_a_r_t__f_o_r_m() and all the fill-out form
  1574.       tags are special.  See their respective sections.
  1575.  
  1576.      CCCCRRRREEEEAAAATTTTIIIINNNNGGGG FFFFIIIILLLLLLLL----OOOOUUUUTTTT FFFFOOOORRRRMMMMSSSS::::
  1577.       _G_e_n_e_r_a_l _n_o_t_e    The various form-creating methods all return
  1578.  
  1579.  
  1580.  
  1581.      Page 24                        (printed 10/23/98)
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  1589.  
  1590.  
  1591.  
  1592.       strings to the caller, containing the    tag or tags that will
  1593.       create the requested form element.  You are responsible for
  1594.       actually printing out    these strings.    It's set up this way
  1595.       so that you can place    formatting tags    around the form
  1596.       elements.
  1597.  
  1598.       _A_n_o_t_h_e_r _n_o_t_e The default values that you specify for the
  1599.       forms    are only used the ffffiiiirrrrsssstttt    time the script    is invoked
  1600.       (when    there is no query string).  On subsequent invocations
  1601.       of the script    (when there is a query string),    the former
  1602.       values are used even if they are blank.
  1603.  
  1604.       If you want to change    the value of a field from its previous
  1605.       value, you have two choices:
  1606.  
  1607.       (1) call the _p_a_r_a_m() method to set it.
  1608.  
  1609.       (2) use the -override    (alias -force) parameter (a new
  1610.       feature in version 2.15).  This forces the default value to
  1611.       be used, regardless of the previous value:
  1612.  
  1613.          print $query->textfield(-name=>'field_name',
  1614.                      -default=>'starting value',
  1615.                      -override=>1,
  1616.                      -size=>50,
  1617.                      -maxlength=>80);
  1618.  
  1619.       _Y_e_t _a_n_o_t_h_e_r _n_o_t_e By default, the text    and labels of form
  1620.       elements are escaped according to HTML rules.     This means
  1621.       that you can safely use "<CLICK ME>" as the label for    a
  1622.       button.  However, it also interferes with your ability to
  1623.       incorporate special HTML character sequences,    such as
  1624.       Á, into your fields.  If you wish to turn off
  1625.       automatic escaping, call the _a_u_t_o_E_s_c_a_p_e() method with    a
  1626.       false    value immediately after    creating the CGI object:
  1627.  
  1628.          $query = new CGI;
  1629.          $query->autoEscape(undef);
  1630.  
  1631.  
  1632.  
  1633.       CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAANNNN IIIISSSSIIIINNNNDDDDEEEEXXXX TTTTAAAAGGGG
  1634.  
  1635.          print $query->isindex(-action=>$action);
  1636.  
  1637.            -or-
  1638.  
  1639.          print $query->isindex($action);
  1640.  
  1641.       Prints out an    <ISINDEX> tag.    Not very exciting.  The
  1642.       parameter -action specifies the URL of the script to process
  1643.       the query.  The default is to    process    the query with the
  1644.  
  1645.  
  1646.  
  1647.      Page 25                        (printed 10/23/98)
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  1655.  
  1656.  
  1657.  
  1658.       current script.
  1659.  
  1660.       SSSSTTTTAAAARRRRTTTTIIIINNNNGGGG AAAANNNNDDDD EEEENNNNDDDDIIIINNNNGGGG AAAA    FFFFOOOORRRRMMMM
  1661.  
  1662.           print $query->startform(-method=>$method,
  1663.                       -action=>$action,
  1664.                       -encoding=>$encoding);
  1665.         <... various form stuff    ...>
  1666.           print $query->endform;
  1667.  
  1668.           -or-
  1669.  
  1670.           print $query->startform($method,$action,$encoding);
  1671.         <... various form stuff    ...>
  1672.           print $query->endform;
  1673.  
  1674.       _s_t_a_r_t_f_o_r_m() will return a <FORM> tag with the    optional
  1675.       method, action and form encoding that    you specify.  The
  1676.       defaults are:
  1677.           method: POST
  1678.           action: this script
  1679.           encoding:    application/x-www-form-urlencoded
  1680.  
  1681.       _e_n_d_f_o_r_m() returns the    closing    </FORM>    tag.
  1682.  
  1683.       _S_t_a_r_t_f_o_r_m()'s    encoding method    tells the browser how to
  1684.       package the various fields of    the form before    sending    the
  1685.       form to the server.  Two values are possible:
  1686.  
  1687.       aaaapppppppplllliiiiccccaaaattttiiiioooonnnn////xxxx----wwwwwwwwwwww----ffffoooorrrrmmmm----uuuurrrrlllleeeennnnccccooooddddeeeedddd
  1688.           This is the older type of encoding used by all
  1689.           browsers prior to Netscape 2.0.  It is compatible
  1690.           with many CGI    scripts    and is suitable    for short
  1691.           fields containing text data.    For your convenience,
  1692.           CGI.pm stores    the name of this encoding type in
  1693.           $$$$CCCCGGGGIIII::::::::UUUURRRRLLLL____EEEENNNNCCCCOOOODDDDEEEEDDDD.
  1694.  
  1695.       mmmmuuuullllttttiiiippppaaaarrrrtttt////ffffoooorrrrmmmm----ddddaaaattttaaaa
  1696.           This is the newer type of encoding introduced    by
  1697.           Netscape 2.0.     It is suitable    for forms that contain
  1698.           very large fields or that are    intended for
  1699.           transferring binary data.  Most importantly, it
  1700.           enables the "file upload" feature of Netscape    2.0
  1701.           forms.  For your convenience,    CGI.pm stores the name
  1702.           of this encoding type    in &&&&CCCCGGGGIIII::::::::MMMMUUUULLLLTTTTIIIIPPPPAAAARRRRTTTT
  1703.  
  1704.           Forms    that use this type of encoding are not easily
  1705.           interpreted by CGI scripts unless they use CGI.pm or
  1706.           another library designed to handle them.
  1707.  
  1708.           For compatibility, the _s_t_a_r_t_f_o_r_m() method uses the
  1709.           older    form of    encoding by default.  If you want to
  1710.  
  1711.  
  1712.  
  1713.      Page 26                        (printed 10/23/98)
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  1721.  
  1722.  
  1723.  
  1724.           use the newer    form of    encoding by default, you can
  1725.           call ssssttttaaaarrrrtttt____mmmmuuuullllttttiiiippppaaaarrrrtttt____ffffoooorrrrmmmm(((()))) instead of ssssttttaaaarrrrttttffffoooorrrrmmmm(((()))).
  1726.  
  1727.           JAVASCRIPTING: The ----nnnnaaaammmmeeee and ----oooonnnnSSSSuuuubbbbmmmmiiiitttt parameters
  1728.           are provided for use with JavaScript.     The -name
  1729.           parameter gives the form a name so that it can be
  1730.           identified and manipulated by    JavaScript functions.
  1731.           -onSubmit should point to a JavaScript function that
  1732.           will be executed just    before the form    is submitted
  1733.           to your server.  You can use this opportunity    to
  1734.           check    the contents of    the form for consistency and
  1735.           completeness.     If you    find something wrong, you can
  1736.           put up an alert box or maybe fix things up yourself.
  1737.           You can abort    the submission by returning false from
  1738.           this function.
  1739.  
  1740.           Usually the bulk of JavaScript functions are defined
  1741.           in a <SCRIPT>    block in the HTML header and -onSubmit
  1742.           points to one    of these function call.     See
  1743.           _s_t_a_r_t__h_t_m_l() for details.
  1744.  
  1745.       CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA TTTTEEEEXXXXTTTT FFFFIIIIEEEELLLLDDDD
  1746.  
  1747.           print $query->textfield(-name=>'field_name',
  1748.                       -default=>'starting value',
  1749.                       -size=>50,
  1750.                       -maxlength=>80);
  1751.           -or-
  1752.  
  1753.           print $query->textfield('field_name','starting value',50,80);
  1754.  
  1755.       _t_e_x_t_f_i_e_l_d() will return a text input field.
  1756.  
  1757.       PPPPaaaarrrraaaammmmeeeetttteeeerrrrssss
  1758.  
  1759.       1.      The first parameter is the required name for the
  1760.           field    (-name).
  1761.  
  1762.       2.      The optional second parameter    is the default
  1763.           starting value for the field contents    (-default).
  1764.  
  1765.       3.      The optional third parameter is the size of the
  1766.           field    in
  1767.             characters (-size).
  1768.  
  1769.       4.      The optional fourth parameter    is the maximum number
  1770.           of characters    the
  1771.             field will accept (-maxlength).
  1772.  
  1773.           As with all these methods, the field will be
  1774.           initialized with its previous    contents from earlier
  1775.           invocations of the script.  When the form is
  1776.  
  1777.  
  1778.  
  1779.      Page 27                        (printed 10/23/98)
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  1787.  
  1788.  
  1789.  
  1790.           processed, the value of the text field can be
  1791.           retrieved with:
  1792.  
  1793.              $value    = $query->param('foo');
  1794.  
  1795.           If you want to reset it from its initial value after
  1796.           the script has been called once, you can do so like
  1797.           this:
  1798.  
  1799.              $query->param('foo',"I'm taking over this value!");
  1800.  
  1801.           NEW AS OF VERSION 2.15: If you don't want the    field
  1802.           to take on its previous value, you can force its
  1803.           current value    by using the -override (alias -force)
  1804.           parameter:
  1805.  
  1806.               print $query->textfield(-name=>'field_name',
  1807.                           -default=>'starting value',
  1808.                           -override=>1,
  1809.                           -size=>50,
  1810.                           -maxlength=>80);
  1811.  
  1812.           JAVASCRIPTING: You can also provide ----oooonnnnCCCChhhhaaaannnnggggeeee,
  1813.           ----oooonnnnFFFFooooccccuuuussss, ----oooonnnnBBBBlllluuuurrrr, ----oooonnnnMMMMoooouuuusssseeeeOOOOvvvveeeerrrr, ----oooonnnnMMMMoooouuuusssseeeeOOOOuuuutttt and
  1814.           ----oooonnnnSSSSeeeelllleeeecccctttt parameters to register JavaScript event
  1815.           handlers.  The onChange handler will be called
  1816.           whenever the user changes the    contents of the    text
  1817.           field.  You can do text validation if    you like.
  1818.           onFocus and onBlur are called    respectively when the
  1819.           insertion point moves    into and out of    the text
  1820.           field.  onSelect is called when the user changes the
  1821.           portion of the text that is selected.
  1822.  
  1823.       CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA BBBBIIIIGGGG TTTTEEEEXXXXTTTT FFFFIIIIEEEELLLLDDDD
  1824.  
  1825.          print $query->textarea(-name=>'foo',
  1826.                     -default=>'starting    value',
  1827.                     -rows=>10,
  1828.                     -columns=>50);
  1829.  
  1830.           -or
  1831.  
  1832.          print $query->textarea('foo','starting value',10,50);
  1833.  
  1834.       _t_e_x_t_a_r_e_a() is    just like textfield, but it allows you to
  1835.       specify rows and columns for a multiline text    entry box.
  1836.       You can provide a starting value for the field, which    can be
  1837.       long and contain multiple lines.
  1838.  
  1839.       JAVASCRIPTING: The ----oooonnnnCCCChhhhaaaannnnggggeeee,    ----oooonnnnFFFFooooccccuuuussss, ----oooonnnnBBBBlllluuuurrrr ,
  1840.       ----oooonnnnMMMMoooouuuusssseeeeOOOOvvvveeeerrrr,    ----oooonnnnMMMMoooouuuusssseeeeOOOOuuuutttt, and ----oooonnnnSSSSeeeelllleeeecccctttt parameters are
  1841.       recognized.  See _t_e_x_t_f_i_e_l_d().
  1842.  
  1843.  
  1844.  
  1845.      Page 28                        (printed 10/23/98)
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  1853.  
  1854.  
  1855.  
  1856.       CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA PPPPAAAASSSSSSSSWWWWOOOORRRRDDDD FFFFIIIIEEEELLLLDDDD
  1857.  
  1858.          print $query->password_field(-name=>'secret',
  1859.                       -value=>'starting value',
  1860.                       -size=>50,
  1861.                       -maxlength=>80);
  1862.           -or-
  1863.  
  1864.          print $query->password_field('secret','starting value',50,80);
  1865.  
  1866.       _p_a_s_s_w_o_r_d__f_i_e_l_d() is identical    to _t_e_x_t_f_i_e_l_d(),    except that
  1867.       its contents will be starred out on the web page.
  1868.  
  1869.       JAVASCRIPTING: The ----oooonnnnCCCChhhhaaaannnnggggeeee,    ----oooonnnnFFFFooooccccuuuussss, ----oooonnnnBBBBlllluuuurrrr,
  1870.       ----oooonnnnMMMMoooouuuusssseeeeOOOOvvvveeeerrrr,    ----oooonnnnMMMMoooouuuusssseeeeOOOOuuuutttt and    ----oooonnnnSSSSeeeelllleeeecccctttt parameters are
  1871.       recognized.  See _t_e_x_t_f_i_e_l_d().
  1872.  
  1873.       CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA FFFFIIIILLLLEEEE UUUUPPPPLLLLOOOOAAAADDDD FFFFIIIIEEEELLLLDDDD
  1874.  
  1875.           print $query->filefield(-name=>'uploaded_file',
  1876.                       -default=>'starting value',
  1877.                       -size=>50,
  1878.                       -maxlength=>80);
  1879.           -or-
  1880.  
  1881.           print $query->filefield('uploaded_file','starting    value',50,80);
  1882.  
  1883.       _f_i_l_e_f_i_e_l_d() will return a file upload    field for Netscape 2.0
  1884.       browsers.  In    order to take full advantage of    this _y_o_u _m_u_s_t
  1885.       _u_s_e _t_h_e _n_e_w _m_u_l_t_i_p_a_r_t    _e_n_c_o_d_i_n_g _s_c_h_e_m_e    for the    form.  You can
  1886.       do this either by calling ssssttttaaaarrrrttttffffoooorrrrmmmm(((())))    with an    encoding type
  1887.       of $$$$CCCCGGGGIIII::::::::MMMMUUUULLLLTTTTIIIIPPPPAAAARRRRTTTT, or by calling the    new method
  1888.       ssssttttaaaarrrrtttt____mmmmuuuullllttttiiiippppaaaarrrrtttt____ffffoooorrrrmmmm(((()))) instead of vanilla ssssttttaaaarrrrttttffffoooorrrrmmmm(((()))).
  1889.  
  1890.       PPPPaaaarrrraaaammmmeeeetttteeeerrrrssss
  1891.  
  1892.       1.      The first parameter is the required name for the
  1893.           field    (-name).
  1894.  
  1895.       2.      The optional second parameter    is the starting    value
  1896.           for the field    contents to be used as the default
  1897.           file name (-default).
  1898.  
  1899.           The beta2 version of Netscape    2.0 currently doesn't
  1900.           pay any attention to this field, and so the starting
  1901.           value    will always be blank.  Worse, the field    loses
  1902.           its "sticky" behavior    and forgets its    previous
  1903.           contents.  The starting value    field is called    for in
  1904.           the HTML specification, however, and possibly    later
  1905.           versions of Netscape will honor it.
  1906.  
  1907.  
  1908.  
  1909.  
  1910.  
  1911.      Page 29                        (printed 10/23/98)
  1912.  
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  1919.  
  1920.  
  1921.  
  1922.       3.      The optional third parameter is the size of the
  1923.           field    in characters (-size).
  1924.  
  1925.       4.      The optional fourth parameter    is the maximum number
  1926.           of characters    the field will accept (-maxlength).
  1927.  
  1928.           When the form    is processed, you can retrieve the
  1929.           entered filename by calling _p_a_r_a_m().
  1930.  
  1931.              $filename = $query->param('uploaded_file');
  1932.  
  1933.           In Netscape Navigator    2.0, the filename that gets
  1934.           returned is the full local filename on the rrrreeeemmmmooootttteeee
  1935.           uuuusssseeeerrrr''''ssss machine.  If the remote user is on a Unix
  1936.           machine, the filename    will follow Unix conventions:
  1937.  
  1938.               /path/to/the/file
  1939.  
  1940.           On an    MS-DOS/Windows and OS/2    machines, the filename
  1941.           will follow DOS conventions:
  1942.  
  1943.               C:\PATH\TO\THE\FILE.MSW
  1944.  
  1945.           On a Macintosh machine, the filename will follow Mac
  1946.           conventions:
  1947.  
  1948.               HD 40:Desktop    Folder:Sort Through:Reminders
  1949.  
  1950.           The filename returned    is also    a file handle.    You
  1951.           can read the contents    of the file using standard
  1952.           Perl file reading calls:
  1953.  
  1954.               # Read a text    file and print it out
  1955.               while    (<$filename>) {
  1956.                  print;
  1957.               }
  1958.  
  1959.               # Copy a binary file to somewhere safe
  1960.               open (OUTFILE,">>/usr/local/web/users/feedback");
  1961.               while    ($bytesread=read($filename,$buffer,1024)) {
  1962.                  print OUTFILE $buffer;
  1963.               }
  1964.  
  1965.           When a file is uploaded the browser usually sends
  1966.           along    some information along with it in the format
  1967.           of headers.  The information usually includes    the
  1968.           MIME content type.  Future browsers may send other
  1969.           information as well (such as modification date and
  1970.           size). To retrieve this information, call
  1971.           _u_p_l_o_a_d_I_n_f_o().     It returns a reference    to an
  1972.           associative array containing all the document
  1973.           headers.
  1974.  
  1975.  
  1976.  
  1977.      Page 30                        (printed 10/23/98)
  1978.  
  1979.  
  1980.  
  1981.  
  1982.  
  1983.  
  1984.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  1985.  
  1986.  
  1987.  
  1988.              $filename = $query->param('uploaded_file');
  1989.              $type = $query->uploadInfo($filename)->{'Content-Type'};
  1990.              unless    ($type eq 'text/html') {
  1991.                 die    "HTML FILES ONLY!";
  1992.              }
  1993.  
  1994.           If you are using a machine that recognizes "text"
  1995.           and "binary" data modes, be sure to understand when
  1996.           and how to use them (see the Camel book). Otherwise
  1997.           you may find that binary files are corrupted during
  1998.           file uploads.
  1999.  
  2000.           JAVASCRIPTING: The ----oooonnnnCCCChhhhaaaannnnggggeeee,    ----oooonnnnFFFFooooccccuuuussss, ----oooonnnnBBBBlllluuuurrrr,
  2001.           ----oooonnnnMMMMoooouuuusssseeeeOOOOvvvveeeerrrr,    ----oooonnnnMMMMoooouuuusssseeeeOOOOuuuutttt and    ----oooonnnnSSSSeeeelllleeeecccctttt parameters
  2002.           are recognized.  See _t_e_x_t_f_i_e_l_d() for details.
  2003.  
  2004.       CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA PPPPOOOOPPPPUUUUPPPP MMMMEEEENNNNUUUU
  2005.  
  2006.          print $query->popup_menu('menu_name',
  2007.                       ['eenie','meenie','minie'],
  2008.                       'meenie');
  2009.  
  2010.         -or-
  2011.  
  2012.          %labels = ('eenie'=>'your first choice',
  2013.             'meenie'=>'your    second choice',
  2014.             'minie'=>'your third choice');
  2015.          print $query->popup_menu('menu_name',
  2016.                       ['eenie','meenie','minie'],
  2017.                       'meenie',\%labels);
  2018.  
  2019.           -or (named parameter style)-
  2020.  
  2021.          print $query->popup_menu(-name=>'menu_name',
  2022.                       -values=>['eenie','meenie','minie'],
  2023.                       -default=>'meenie',
  2024.                       -labels=>\%labels);
  2025.  
  2026.       _p_o_p_u_p__m_e_n_u() creates a menu.
  2027.  
  2028.       1.      The required first argument is the menu's name
  2029.           (-name).
  2030.  
  2031.       2.      The required second argument (-values) is an array
  2032.           rrrreeeeffffeeeerrrreeeennnncccceeee containing the list    of menu    items in the
  2033.           menu.     You can pass the method an anonymous array,
  2034.           as shown in the example, or a    reference to a named
  2035.           array, such as "\@foo".
  2036.  
  2037.       3.      The optional third parameter (-default) is the name
  2038.           of the default menu choice.  If not specified, the
  2039.           first    item will be the default.  The values of the
  2040.  
  2041.  
  2042.  
  2043.      Page 31                        (printed 10/23/98)
  2044.  
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  2051.  
  2052.  
  2053.  
  2054.           previous choice will be maintained across queries.
  2055.  
  2056.       4.      The optional fourth parameter    (-labels) is provided
  2057.           for people who want to use different values for the
  2058.           user-visible label inside the    popup menu nd the
  2059.           value    returned to your script.  It's a pointer to an
  2060.           associative array relating menu values to user-
  2061.           visible labels.  If you leave    this parameter blank,
  2062.           the menu values will be displayed by default.     (You
  2063.           can also leave a label undefined if you want to).
  2064.  
  2065.           When the form    is processed, the selected value of
  2066.           the popup menu can be    retrieved using:
  2067.  
  2068.             $popup_menu_value = $query->param('menu_name');
  2069.  
  2070.           JAVASCRIPTING: _p_o_p_u_p__m_e_n_u() recognizes the following
  2071.           event    handlers:  ----oooonnnnCCCChhhhaaaannnnggggeeee, ----oooonnnnFFFFooooccccuuuussss,    ----oooonnnnMMMMoooouuuusssseeeeOOOOvvvveeeerrrr,
  2072.           ----oooonnnnMMMMoooouuuusssseeeeOOOOuuuutttt, and ----oooonnnnBBBBlllluuuurrrr.  See the _t_e_x_t_f_i_e_l_d()
  2073.           section for details on when these handlers are
  2074.           called.
  2075.  
  2076.       CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA SSSSCCCCRRRROOOOLLLLLLLLIIIINNNNGGGG LLLLIIIISSSSTTTT
  2077.  
  2078.          print $query->scrolling_list('list_name',
  2079.                       ['eenie','meenie','minie','moe'],
  2080.                       ['eenie','moe'],5,'true');
  2081.         -or-
  2082.  
  2083.          print $query->scrolling_list('list_name',
  2084.                       ['eenie','meenie','minie','moe'],
  2085.                       ['eenie','moe'],5,'true',
  2086.                       \%labels);
  2087.  
  2088.           -or-
  2089.  
  2090.          print $query->scrolling_list(-name=>'list_name',
  2091.                       -values=>['eenie','meenie','minie','moe'],
  2092.                       -default=>['eenie','moe'],
  2093.                       -size=>5,
  2094.                       -multiple=>'true',
  2095.                       -labels=>\%labels);
  2096.  
  2097.       _s_c_r_o_l_l_i_n_g__l_i_s_t() creates a scrolling list.
  2098.  
  2099.       PPPPaaaarrrraaaammmmeeeetttteeeerrrrssss::::
  2100.  
  2101.       1.      The first and    second arguments are the list name
  2102.           (-name) and values (-values).     As in the popup menu,
  2103.           the second argument should be    an array reference.
  2104.  
  2105.  
  2106.  
  2107.  
  2108.  
  2109.      Page 32                        (printed 10/23/98)
  2110.  
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  2117.  
  2118.  
  2119.  
  2120.       2.      The optional third argument (-default) can be    either
  2121.           a reference to a list    containing the values to be
  2122.           selected by default, or can be a single value    to
  2123.           select.  If this argument is missing or undefined,
  2124.           then nothing is selected when    the list first
  2125.           appears.  In the named parameter version, you    can
  2126.           use the synonym "-defaults" for this parameter.
  2127.  
  2128.       3.      The optional fourth argument is the size of the list
  2129.           (-size).
  2130.  
  2131.       4.      The optional fifth argument can be set to true to
  2132.           allow    multiple simultaneous selections (-multiple).
  2133.           Otherwise only one selection will be allowed at a
  2134.           time.
  2135.  
  2136.       5.      The optional sixth argument is a pointer to an
  2137.           associative array containing long user-visible
  2138.           labels for the list items (-labels).    If not
  2139.           provided, the    values will be displayed.
  2140.  
  2141.           When this form is processed, all selected list items
  2142.           will be returned as a    list under the parameter name
  2143.           'list_name'.    The values of the selected items can
  2144.           be retrieved with:
  2145.  
  2146.             @selected = $query->param('list_name');
  2147.  
  2148.  
  2149.           JAVASCRIPTING: _s_c_r_o_l_l_i_n_g__l_i_s_t() recognizes the
  2150.           following event handlers: ----oooonnnnCCCChhhhaaaannnnggggeeee, ----oooonnnnFFFFooooccccuuuussss,
  2151.           ----oooonnnnMMMMoooouuuusssseeeeOOOOvvvveeeerrrr,    ----oooonnnnMMMMoooouuuusssseeeeOOOOuuuutttt and    ----oooonnnnBBBBlllluuuurrrr.  See
  2152.           _t_e_x_t_f_i_e_l_d() for the description of when these
  2153.           handlers are called.
  2154.  
  2155.       CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA GGGGRRRROOOOUUUUPPPP OOOOFFFF RRRREEEELLLLAAAATTTTEEEEDDDD CCCCHHHHEEEECCCCKKKKBBBBOOOOXXXXEEEESSSS
  2156.  
  2157.          print $query->checkbox_group(-name=>'group_name',
  2158.                       -values=>['eenie','meenie','minie','moe'],
  2159.                       -default=>['eenie','moe'],
  2160.                       -linebreak=>'true',
  2161.                       -labels=>\%labels);
  2162.  
  2163.          print $query->checkbox_group('group_name',
  2164.                       ['eenie','meenie','minie','moe'],
  2165.                       ['eenie','moe'],'true',\%labels);
  2166.  
  2167.          HTML3-COMPATIBLE BROWSERS ONLY:
  2168.  
  2169.  
  2170.  
  2171.  
  2172.  
  2173.  
  2174.  
  2175.      Page 33                        (printed 10/23/98)
  2176.  
  2177.  
  2178.  
  2179.  
  2180.  
  2181.  
  2182.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  2183.  
  2184.  
  2185.  
  2186.          print $query->checkbox_group(-name=>'group_name',
  2187.                       -values=>['eenie','meenie','minie','moe'],
  2188.                       -rows=2,-columns=>2);
  2189.  
  2190.  
  2191.       _c_h_e_c_k_b_o_x__g_r_o_u_p() creates a list of checkboxes    that are
  2192.       related by the same name.
  2193.  
  2194.       PPPPaaaarrrraaaammmmeeeetttteeeerrrrssss::::
  2195.  
  2196.       1.      The first and    second arguments are the checkbox name
  2197.           and values, respectively (-name and -values).     As in
  2198.           the popup menu, the second argument should be    an
  2199.           array    reference.  These values are used for the
  2200.           user-readable    labels printed next to the checkboxes
  2201.           as well as for the values passed to your script in
  2202.           the query string.
  2203.  
  2204.       2.      The optional third argument (-default) can be    either
  2205.           a reference to a list    containing the values to be
  2206.           checked by default, or can be    a single value to
  2207.           checked.  If this argument is    missing    or undefined,
  2208.           then nothing is selected when    the list first
  2209.           appears.
  2210.  
  2211.       3.      The optional fourth argument (-linebreak) can    be set
  2212.           to true to place line    breaks between the checkboxes
  2213.           so that they appear as a vertical list.  Otherwise,
  2214.           they will be strung together on a horizontal line.
  2215.  
  2216.       4.      The optional fifth argument is a pointer to an
  2217.           associative array relating the checkbox values to
  2218.           the user-visible labels that will be printed next to
  2219.           them (-labels).  If not provided, the    values will be
  2220.           used as the default.
  2221.  
  2222.       5.      HHHHTTTTMMMMLLLL3333----ccccoooommmmppppaaaattttiiiibbbblllleeee bbbbrrrroooowwwwsssseeeerrrrssss (such as Netscape) can
  2223.           take advantage of the    optional parameters ----rrrroooowwwwssss, and
  2224.           ----ccccoooolllluuuummmmnnnnssss.  These parameters cause _c_h_e_c_k_b_o_x__g_r_o_u_p()
  2225.           to return an HTML3 compatible    table containing the
  2226.           checkbox group formatted with    the specified number
  2227.           of rows and columns.    You can    provide    just the
  2228.           -columns parameter if    you wish; checkbox_group will
  2229.           calculate the    correct    number of rows for you.
  2230.  
  2231.           To include row and column headings in    the returned
  2232.           table, you can use the ----rrrroooowwwwhhhheeeeaaaaddddeeeerrrrssss and ----ccccoooollllhhhheeeeaaaaddddeeeerrrrssss
  2233.           parameters.  Both of these accept a pointer to an
  2234.           array    of headings to use.  The headings are just
  2235.           decorative.  They don't reorganize the
  2236.           interpretation of the    checkboxes -- they're still a
  2237.           single named unit.
  2238.  
  2239.  
  2240.  
  2241.      Page 34                        (printed 10/23/98)
  2242.  
  2243.  
  2244.  
  2245.  
  2246.  
  2247.  
  2248.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  2249.  
  2250.  
  2251.  
  2252.           When the form    is processed, all checked boxes    will
  2253.           be returned as a list    under the parameter name
  2254.           'group_name'.     The values of the "on"    checkboxes can
  2255.           be retrieved with:
  2256.  
  2257.             @turned_on = $query->param('group_name');
  2258.  
  2259.           The value returned by    _c_h_e_c_k_b_o_x__g_r_o_u_p() is actually
  2260.           an array of button elements.    You can    capture    them
  2261.           and use them within tables, lists, or    in other
  2262.           creative ways:
  2263.  
  2264.               @h = $query->checkbox_group(-name=>'group_name',-values=>\@values);
  2265.               &use_in_creative_way(@h);
  2266.  
  2267.           JAVASCRIPTING: _c_h_e_c_k_b_o_x__g_r_o_u_p() recognizes the
  2268.           ----oooonnnnCCCClllliiiicccckkkk parameter.  This specifies a    JavaScript
  2269.           code fragment    or function call to be executed    every
  2270.           time the user    clicks on any of the buttons in    the
  2271.           group.  You can retrieve the identity    of the
  2272.           particular button clicked on using the "this"
  2273.           variable.
  2274.  
  2275.       CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA SSSSTTTTAAAANNNNDDDDAAAALLLLOOOONNNNEEEE    CCCCHHHHEEEECCCCKKKKBBBBOOOOXXXX
  2276.  
  2277.           print $query->checkbox(-name=>'checkbox_name',
  2278.                      -checked=>'checked',
  2279.                      -value=>'ON',
  2280.                      -label=>'CLICK ME');
  2281.  
  2282.           -or-
  2283.  
  2284.           print $query->checkbox('checkbox_name','checked','ON','CLICK ME');
  2285.  
  2286.       _c_h_e_c_k_b_o_x() is    used to    create an isolated checkbox that isn't
  2287.       logically related to any others.
  2288.  
  2289.       PPPPaaaarrrraaaammmmeeeetttteeeerrrrssss::::
  2290.  
  2291.       1.      The first parameter is the required name for the
  2292.           checkbox (-name).  It    will also be used for the
  2293.           user-readable    label printed next to the checkbox.
  2294.  
  2295.       2.      The optional second parameter    (-checked) specifies
  2296.           that the checkbox is turned on by default.  Synonyms
  2297.           are -selected    and -on.
  2298.  
  2299.       3.      The optional third parameter (-value)    specifies the
  2300.           value    of the checkbox    when it    is checked.  If    not
  2301.           provided, the    word "on" is assumed.
  2302.  
  2303.  
  2304.  
  2305.  
  2306.  
  2307.      Page 35                        (printed 10/23/98)
  2308.  
  2309.  
  2310.  
  2311.  
  2312.  
  2313.  
  2314.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  2315.  
  2316.  
  2317.  
  2318.       4.      The optional fourth parameter    (-label) is the    user-
  2319.           readable label to be attached    to the checkbox.  If
  2320.           not provided,    the checkbox name is used.
  2321.  
  2322.           The value of the checkbox can    be retrieved using:
  2323.  
  2324.               $turned_on = $query->param('checkbox_name');
  2325.  
  2326.           JAVASCRIPTING: _c_h_e_c_k_b_o_x() recognizes the ----oooonnnnCCCClllliiiicccckkkk
  2327.           parameter.  See _c_h_e_c_k_b_o_x__g_r_o_u_p() for further
  2328.           details.
  2329.  
  2330.       CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA RRRRAAAADDDDIIIIOOOO BBBBUUUUTTTTTTTTOOOONNNN GGGGRRRROOOOUUUUPPPP
  2331.  
  2332.          print $query->radio_group(-name=>'group_name',
  2333.                        -values=>['eenie','meenie','minie'],
  2334.                        -default=>'meenie',
  2335.                        -linebreak=>'true',
  2336.                        -labels=>\%labels);
  2337.  
  2338.           -or-
  2339.  
  2340.          print $query->radio_group('group_name',['eenie','meenie','minie'],
  2341.                             'meenie','true',\%labels);
  2342.  
  2343.          HTML3-COMPATIBLE BROWSERS ONLY:
  2344.  
  2345.          print $query->radio_group(-name=>'group_name',
  2346.                        -values=>['eenie','meenie','minie','moe'],
  2347.                        -rows=2,-columns=>2);
  2348.  
  2349.       _r_a_d_i_o__g_r_o_u_p()    creates    a set of logically-related radio
  2350.       buttons (turning one member of the group on turns the    others
  2351.       off)
  2352.  
  2353.       PPPPaaaarrrraaaammmmeeeetttteeeerrrrssss::::
  2354.  
  2355.       1.      The first argument is    the name of the    group and is
  2356.           required (-name).
  2357.  
  2358.       2.      The second argument (-values)    is the list of values
  2359.           for the radio    buttons.  The values and the labels
  2360.           that appear on the page are identical.  Pass an
  2361.           array    _r_e_f_e_r_e_n_c_e in the second    argument, either using
  2362.           an anonymous array, as shown,    or by referencing a
  2363.           named    array as in "\@foo".
  2364.  
  2365.       3.      The optional third parameter (-default) is the name
  2366.           of the default button    to turn    on. If not specified,
  2367.           the first item will be the default.  You can provide
  2368.           a nonexistent    button name, such as "-" to start up
  2369.           with no buttons selected.
  2370.  
  2371.  
  2372.  
  2373.      Page 36                        (printed 10/23/98)
  2374.  
  2375.  
  2376.  
  2377.  
  2378.  
  2379.  
  2380.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  2381.  
  2382.  
  2383.  
  2384.       4.      The optional fourth parameter    (-linebreak) can be
  2385.           set to 'true'    to put line breaks between the
  2386.           buttons, creating a vertical list.
  2387.  
  2388.       5.      The optional fifth parameter (-labels) is a pointer
  2389.           to an    associative array relating the radio button
  2390.           values to user-visible labels    to be used in the
  2391.           display.  If not provided, the values    themselves are
  2392.           displayed.
  2393.  
  2394.       6.      HHHHTTTTMMMMLLLL3333----ccccoooommmmppppaaaattttiiiibbbblllleeee bbbbrrrroooowwwwsssseeeerrrrssss (such as Netscape) can
  2395.           take advantage of the    optional parameters ----rrrroooowwwwssss, and
  2396.           ----ccccoooolllluuuummmmnnnnssss.  These parameters cause _r_a_d_i_o__g_r_o_u_p() to
  2397.           return an HTML3 compatible table containing the
  2398.           radio    group formatted    with the specified number of
  2399.           rows and columns.  You can provide just the -columns
  2400.           parameter if you wish; radio_group will calculate
  2401.           the correct number of    rows for you.
  2402.  
  2403.           To include row and column headings in    the returned
  2404.           table, you can use the ----rrrroooowwwwhhhheeeeaaaaddddeeeerrrr and    ----ccccoooollllhhhheeeeaaaaddddeeeerrrr
  2405.           parameters.  Both of these accept a pointer to an
  2406.           array    of headings to use.  The headings are just
  2407.           decorative.  They don't reorganize the interpetation
  2408.           of the radio buttons -- they're still    a single named
  2409.           unit.
  2410.  
  2411.           When the form    is processed, the selected radio
  2412.           button can be    retrieved using:
  2413.  
  2414.             $which_radio_button = $query->param('group_name');
  2415.  
  2416.           The value returned by    _r_a_d_i_o__g_r_o_u_p() is actually an
  2417.           array    of button elements.  You can capture them and
  2418.           use them within tables, lists, or in other creative
  2419.           ways:
  2420.  
  2421.               @h = $query->radio_group(-name=>'group_name',-values=>\@values);
  2422.               &use_in_creative_way(@h);
  2423.  
  2424.  
  2425.       CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA SSSSUUUUBBBBMMMMIIIITTTT BBBBUUUUTTTTTTTTOOOONNNN
  2426.  
  2427.          print $query->submit(-name=>'button_name',
  2428.                   -value=>'value');
  2429.  
  2430.           -or-
  2431.  
  2432.          print $query->submit('button_name','value');
  2433.  
  2434.       _s_u_b_m_i_t() will    create the query submission button.  Every
  2435.       form should have one of these.
  2436.  
  2437.  
  2438.  
  2439.      Page 37                        (printed 10/23/98)
  2440.  
  2441.  
  2442.  
  2443.  
  2444.  
  2445.  
  2446.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  2447.  
  2448.  
  2449.  
  2450.       PPPPaaaarrrraaaammmmeeeetttteeeerrrrssss::::
  2451.  
  2452.       1.      The first argument (-name) is    optional.  You can
  2453.           give the button a name if you    have several
  2454.           submission buttons in    your form and you want to
  2455.           distinguish between them.  The name will also    be
  2456.           used as the user-visible label.  Be aware that a few
  2457.           older    browsers don't deal with this correctly    and
  2458.           nnnneeeevvvveeeerrrr    send back a value from a button.
  2459.  
  2460.       2.      The second argument (-value) is also optional.  This
  2461.           gives    the button a value that    will be    passed to your
  2462.           script in the    query string.
  2463.  
  2464.           You can figure out which button was pressed by using
  2465.           different values for each one:
  2466.  
  2467.                $which_one = $query->param('button_name');
  2468.  
  2469.           JAVASCRIPTING: _r_a_d_i_o__g_r_o_u_p() recognizes the ----oooonnnnCCCClllliiiicccckkkk
  2470.           parameter.  See _c_h_e_c_k_b_o_x__g_r_o_u_p() for further
  2471.           details.
  2472.  
  2473.       CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA RRRREEEESSSSEEEETTTT BBBBUUUUTTTTTTTTOOOONNNN
  2474.  
  2475.          print $query->reset
  2476.  
  2477.       _r_e_s_e_t() creates the "reset" button.  Note that it restores
  2478.       the form to its value    from the last time the script was
  2479.       called, NOT necessarily to the defaults.
  2480.  
  2481.       CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA DDDDEEEEFFFFAAAAUUUULLLLTTTT BBBBUUUUTTTTTTTTOOOONNNN
  2482.  
  2483.          print $query->defaults('button_label')
  2484.  
  2485.       _d_e_f_a_u_l_t_s() creates a button that, when invoked, will cause
  2486.       the form to be completely reset to its defaults, wiping out
  2487.       all the changes the user ever    made.
  2488.  
  2489.       CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA HHHHIIIIDDDDDDDDEEEENNNN FFFFIIIIEEEELLLLDDDD
  2490.  
  2491.           print    $query->hidden(-name=>'hidden_name',
  2492.                        -default=>['value1','value2'...]);
  2493.  
  2494.               -or-
  2495.  
  2496.           print    $query->hidden('hidden_name','value1','value2'...);
  2497.  
  2498.       _h_i_d_d_e_n() produces a text field that can't be seen by the
  2499.       user.     It is useful for passing state    variable information
  2500.       from one invocation of the script to the next.
  2501.  
  2502.  
  2503.  
  2504.  
  2505.      Page 38                        (printed 10/23/98)
  2506.  
  2507.  
  2508.  
  2509.  
  2510.  
  2511.  
  2512.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  2513.  
  2514.  
  2515.  
  2516.       PPPPaaaarrrraaaammmmeeeetttteeeerrrrssss::::
  2517.  
  2518.       1.      The first argument is    required and specifies the
  2519.           name of this field (-name).
  2520.  
  2521.       2.      The second argument is also required and specifies
  2522.           its value (-default).     In the    named parameter    style
  2523.           of calling, you can provide a    single value here or a
  2524.           reference to a whole list
  2525.  
  2526.           Fetch    the value of a hidden field this way:
  2527.  
  2528.                $hidden_value = $query->param('hidden_name');
  2529.  
  2530.           Note,    that just like all the other form elements,
  2531.           the value of a hidden    field is "sticky".  If you
  2532.           want to replace a hidden field with some other
  2533.           values after the script has been called once you'll
  2534.           have to do it    manually:
  2535.  
  2536.                $query->param('hidden_name','new','values','here');
  2537.  
  2538.  
  2539.       CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA CCCCLLLLIIIICCCCKKKKAAAABBBBLLLLEEEE IIIIMMMMAAAAGGGGEEEE BBBBUUUUTTTTTTTTOOOONNNN
  2540.  
  2541.            print $query->image_button(-name=>'button_name',
  2542.                       -src=>'/source/URL',
  2543.                       -align=>'MIDDLE');
  2544.  
  2545.           -or-
  2546.  
  2547.            print $query->image_button('button_name','/source/URL','MIDDLE');
  2548.  
  2549.       _i_m_a_g_e__b_u_t_t_o_n() produces a clickable image.  When it's
  2550.       clicked on the position of the click is returned to your
  2551.       script as "button_name.x" and    "button_name.y", where
  2552.       "button_name"    is the name you've assigned to it.
  2553.  
  2554.       JAVASCRIPTING: _i_m_a_g_e__b_u_t_t_o_n()    recognizes the ----oooonnnnCCCClllliiiicccckkkk
  2555.       parameter.  See _c_h_e_c_k_b_o_x__g_r_o_u_p() for further details.
  2556.  
  2557.       PPPPaaaarrrraaaammmmeeeetttteeeerrrrssss::::
  2558.  
  2559.       1.      The first argument (-name) is    required and specifies
  2560.           the name of this field.
  2561.  
  2562.       2.      The second argument (-src) is    also required and
  2563.           specifies the    URL
  2564.  
  2565.      may be TOP, BOTTOM    or MIDDLE
  2566.       3. The third option (-align, optional) is an alignment type, and
  2567.  
  2568.  
  2569.  
  2570.  
  2571.      Page 39                        (printed 10/23/98)
  2572.  
  2573.  
  2574.  
  2575.  
  2576.  
  2577.  
  2578.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  2579.  
  2580.  
  2581.  
  2582.           Fetch    the value of the button    this way:
  2583.                $x = $query->_p_a_r_a_m('button_name.x');
  2584.                $y = $query->_p_a_r_a_m('button_name.y');
  2585.  
  2586.       CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA JJJJAAAAVVVVAAAASSSSCCCCRRRRIIIIPPPPTTTT    AAAACCCCTTTTIIIIOOOONNNN BBBBUUUUTTTTTTTTOOOONNNN
  2587.  
  2588.            print $query->button(-name=>'button_name',
  2589.                     -value=>'user visible label',
  2590.                     -onClick=>"do_something()");
  2591.  
  2592.           -or-
  2593.  
  2594.            print $query->button('button_name',"do_something()");
  2595.  
  2596.       _b_u_t_t_o_n() produces a button that is compatible    with Netscape
  2597.       2.0's    JavaScript.  When it's pressed the fragment of
  2598.       JavaScript code pointed to by    the ----oooonnnnCCCClllliiiicccckkkk parameter will be
  2599.       executed.  On    non-Netscape browsers this form    element    will
  2600.       probably not even display.
  2601.  
  2602.      NNNNEEEETTTTSSSSCCCCAAAAPPPPEEEE CCCCOOOOOOOOKKKKIIIIEEEESSSS
  2603.       Netscape browsers versions 1.1 and higher support a so-
  2604.       called "cookie" designed to help maintain state within a
  2605.       browser session.  CGI.pm has several methods that support
  2606.       cookies.
  2607.  
  2608.       A cookie is a    name=value pair    much like the named parameters
  2609.       in a CGI query string.  CGI scripts create one or more
  2610.       cookies and send them    to the browser in the HTTP header.
  2611.       The browser maintains    a list of cookies that belong to a
  2612.       particular Web server, and returns them to the CGI script
  2613.       during subsequent interactions.
  2614.  
  2615.       In addition to the required name=value pair, each cookie has
  2616.       several optional attributes:
  2617.  
  2618.       1. an    expiration time
  2619.           This is a time/date string (in a special GMT format)
  2620.           that indicates when a    cookie expires.     The cookie
  2621.           will be saved    and returned to    your script until this
  2622.           expiration date is reached if    the user exits
  2623.           Netscape and restarts    it.  If    an expiration date
  2624.           isn't    specified, the cookie will remain active until
  2625.           the user quits Netscape.
  2626.  
  2627.       2. a domain
  2628.           This is a partial or complete    domain name for    which
  2629.           the cookie is    valid.    The browser will return    the
  2630.           cookie to any    host that matches the partial domain
  2631.           name.     For example, if you specify a domain name of
  2632.           ".capricorn.com", then Netscape will return the
  2633.           cookie to Web    servers    running    on any of the machines
  2634.  
  2635.  
  2636.  
  2637.      Page 40                        (printed 10/23/98)
  2638.  
  2639.  
  2640.  
  2641.  
  2642.  
  2643.  
  2644.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  2645.  
  2646.  
  2647.  
  2648.           "www.capricorn.com", "www2.capricorn.com",
  2649.           "feckless.capricorn.com", etc.  Domain names must
  2650.           contain at least two periods to prevent attempts to
  2651.           match    on top level domains like ".edu".  If no
  2652.           domain is specified, then the    browser    will only
  2653.           return the cookie to servers on the host the cookie
  2654.           originated from.
  2655.  
  2656.       3. a path
  2657.           If you provide a cookie path attribute, the browser
  2658.           will check it    against    your script's URL before
  2659.           returning the    cookie.     For example, if you specify
  2660.           the path "/cgi-bin", then the    cookie will be
  2661.           returned to each of the scripts "/cgi-bin/tally.pl",
  2662.           "/cgi-bin/order.pl", and "/cgi-
  2663.           bin/customer_service/complain.pl", but not to    the
  2664.           script "/cgi-private/site_admin.pl".    By default,
  2665.           path is set to "/", which causes the cookie to be
  2666.           sent to any CGI script on your site.
  2667.  
  2668.       4. a "secure"    flag
  2669.           If the "secure" attribute is set, the    cookie will
  2670.           only be sent to your script if the CGI request is
  2671.           occurring on a secure    channel, such as SSL.
  2672.  
  2673.           The interface    to Netscape cookies is the ccccooooooookkkkiiiieeee(((())))
  2674.           method:
  2675.  
  2676.               $cookie =    $query->cookie(-name=>'sessionID',
  2677.                            -value=>'xyzzy',
  2678.                            -expires=>'+1h',
  2679.                            -path=>'/cgi-bin/database',
  2680.                            -domain=>'.capricorn.org',
  2681.                            -secure=>1);
  2682.               print $query->header(-cookie=>$cookie);
  2683.  
  2684.           ccccooooooookkkkiiiieeee(((()))) creates a new cookie.  Its parameters
  2685.           include:
  2686.  
  2687.       ----nnnnaaaammmmeeee      The name of the cookie (required).  This can be any
  2688.           string at all.  Although Netscape limits its cookie
  2689.           names    to non-whitespace alphanumeric characters,
  2690.           CGI.pm removes this restriction by escaping and
  2691.           unescaping cookies behind the    scenes.
  2692.  
  2693.       ----vvvvaaaalllluuuueeee  The value of the cookie.  This can be    any scalar
  2694.           value, array reference, or even associative array
  2695.           reference.  For example, you can store an entire
  2696.           associative array into a cookie this way:
  2697.  
  2698.               $cookie=$query->cookie(-name=>'family    information',
  2699.                          -value=>\%childrens_ages);
  2700.  
  2701.  
  2702.  
  2703.      Page 41                        (printed 10/23/98)
  2704.  
  2705.  
  2706.  
  2707.  
  2708.  
  2709.  
  2710.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  2711.  
  2712.  
  2713.  
  2714.       ----ppppaaaatttthhhh      The optional partial path for    which this cookie will
  2715.           be valid, as described above.
  2716.  
  2717.       ----ddddoooommmmaaaaiiiinnnn The optional partial domain for which    this cookie
  2718.           will be valid, as described above.
  2719.  
  2720.       ----eeeexxxxppppiiiirrrreeeessss
  2721.           The optional expiration date for this    cookie.     The
  2722.           format is as described in the    section    on the
  2723.           hhhheeeeaaaaddddeeeerrrr(((()))) method:
  2724.  
  2725.               "+1h"     one hour from now
  2726.  
  2727.  
  2728.       ----sssseeeeccccuuuurrrreeee If set to true, this cookie will only    be used    within
  2729.           a secure SSL session.
  2730.  
  2731.           The cookie created by    _c_o_o_k_i_e() must be incorporated
  2732.           into the HTTP    header within the string returned by
  2733.           the _h_e_a_d_e_r() method:
  2734.  
  2735.               print    $query->header(-cookie=>$my_cookie);
  2736.  
  2737.           To create multiple cookies, give _h_e_a_d_e_r() an array
  2738.           reference:
  2739.  
  2740.               $cookie1 = $query->cookie(-name=>'riddle_name',
  2741.                             -value=>"The Sphynx's Question");
  2742.               $cookie2 = $query->cookie(-name=>'answers',
  2743.                             -value=>\%answers);
  2744.               print    $query->header(-cookie=>[$cookie1,$cookie2]);
  2745.  
  2746.           To retrieve a    cookie,    request    it by name by calling
  2747.           _c_o_o_k_i_e() method without the ----vvvvaaaalllluuuueeee parameter:
  2748.  
  2749.               use CGI;
  2750.               $query = new CGI;
  2751.               %answers = $query->cookie(-name=>'answers');
  2752.               # $query->cookie('answers') will work    too!
  2753.  
  2754.           The cookie and CGI namespaces    are separate.  If you
  2755.           have a parameter named 'answers' and a cookie    named
  2756.           'answers', the values    retrieved by _p_a_r_a_m() and
  2757.           _c_o_o_k_i_e() are independent of each other.  However,
  2758.           it's simple to turn a    CGI parameter into a cookie,
  2759.           and vice-versa:
  2760.  
  2761.              # turn a CGI parameter into a cookie
  2762.              $c=$q->cookie(-name=>'answers',-value=>[$q->param('answers')]);
  2763.              # vice-versa
  2764.              $q->param(-name=>'answers',-value=>[$q->cookie('answers')]);
  2765.  
  2766.  
  2767.  
  2768.  
  2769.      Page 42                        (printed 10/23/98)
  2770.  
  2771.  
  2772.  
  2773.  
  2774.  
  2775.  
  2776.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  2777.  
  2778.  
  2779.  
  2780.           See the ccccooooooookkkkiiiieeee....ccccggggiiii example script for    some ideas on
  2781.           how to use cookies effectively.
  2782.  
  2783.           NNNNOOOOTTTTEEEE::::    There appear to    be some    (undocumented)
  2784.           restrictions on Netscape cookies.  In    Netscape 2.01,
  2785.           at least, I haven't been able    to set more than three
  2786.           cookies at a time.  There may    also be    limits on the
  2787.           length of cookies.  If you need to store a lot of
  2788.           information, it's probably better to create a    unique
  2789.           session ID, store it in a cookie, and    use the
  2790.           session ID to    locate an external file/database saved
  2791.           on the server's side of the connection.
  2792.  
  2793.      WWWWOOOORRRRKKKKIIIINNNNGGGG WWWWIIIITTTTHHHH NNNNEEEETTTTSSSSCCCCAAAAPPPPEEEE FFFFRRRRAAAAMMMMEEEESSSS
  2794.       It's possible    for CGI.pm scripts to write into several
  2795.       browser panels and windows using Netscape's frame mechanism.
  2796.       There    are three techniques for defining new frames
  2797.       programmatically:
  2798.  
  2799.       1. Create a <Frameset> document
  2800.           After    writing    out the    HTTP header, instead of
  2801.           creating a standard HTML document using the
  2802.           _s_t_a_r_t__h_t_m_l() call, create a <FRAMESET> document that
  2803.           defines the frames on    the page.  Specify your
  2804.           _s_c_r_i_p_t(s) (with appropriate parameters) as the SRC
  2805.           for each of the frames.
  2806.  
  2807.           There    is no specific support for creating <FRAMESET>
  2808.           sections in CGI.pm, but the HTML is very simple to
  2809.           write.  See the frame    documentation in Netscape's
  2810.           home pages for details
  2811.  
  2812.             http://home.netscape.com/assist/net_sites/frames.html
  2813.  
  2814.  
  2815.       2. Specify the destination for the document in the HTTP header
  2816.           You may provide a ----ttttaaaarrrrggggeeeetttt parameter to the _h_e_a_d_e_r()
  2817.           method:
  2818.  
  2819.               print $q->_h_e_a_d_e_r(-target=>'ResultsWindow');
  2820.  
  2821.           This will tell Netscape to load the output of    your
  2822.           script into the frame    named "ResultsWindow".    If a
  2823.           frame    of that    name doesn't already exist, Netscape
  2824.           will pop up a    new window and load your script's
  2825.           document into    that.  There are a number of magic
  2826.           names    that you can use for targets.  See the frame
  2827.           documents on Netscape's home pages for details.
  2828.  
  2829.       3. Specify the destination for the document in the <FORM> tag
  2830.           You can specify the frame to load in the FORM    tag
  2831.           itself.  With    CGI.pm it looks    like this:
  2832.  
  2833.  
  2834.  
  2835.      Page 43                        (printed 10/23/98)
  2836.  
  2837.  
  2838.  
  2839.  
  2840.  
  2841.  
  2842.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  2843.  
  2844.  
  2845.  
  2846.               print $q->startform(-target=>'ResultsWindow');
  2847.  
  2848.           When your script is reinvoked    by the form, its
  2849.           output will be loaded    into the frame named
  2850.           "ResultsWindow".  If one doesn't already exist a new
  2851.           window will be created.
  2852.  
  2853.           The script "frameset.cgi" in the examples directory
  2854.           shows    one way    to create pages    in which the fill-out
  2855.           form and the response    live in    side-by-side frames.
  2856.  
  2857.      LLLLIIIIMMMMIIIITTTTEEEEDDDD SSSSUUUUPPPPPPPPOOOORRRRTTTT FFFFOOOORRRR CCCCAAAASSSSCCCCAAAADDDDIIIINNNNGGGG SSSSTTTTYYYYLLLLEEEE SSSSHHHHEEEEEEEETTTTSSSS
  2858.       CGI.pm has limited support for HTML3's cascading style
  2859.       sheets (css).     To incorporate    a stylesheet into your
  2860.       document, pass the _s_t_a_r_t__h_t_m_l() method a ----ssssttttyyyylllleeee parameter.
  2861.       The value of this parameter may be a scalar, in which    case
  2862.       it is    incorporated directly into a <STYLE> section, or it
  2863.       may be a hash    reference.  In the latter case you should
  2864.       provide the hash with    one or more of ----ssssrrrrcccc or ----ccccooooddddeeee.  ----ssssrrrrcccc
  2865.       points to a URL where    an externally-defined stylesheet can
  2866.       be found.  ----ccccooooddddeeee points to a scalar value to be incorporated
  2867.       into a <STYLE> section.  Style definitions in    ----ccccooooddddeeee override
  2868.       similarly-named ones in ----ssssrrrrcccc,    hence the name "cascading."
  2869.  
  2870.       You may also specify the type    of the stylesheet by adding
  2871.       the optional ----ttttyyyyppppeeee parameter to the hash pointed to by
  2872.       ----ssssttttyyyylllleeee.  If not specified, the style defaults    to 'text/css'.
  2873.  
  2874.       To refer to a    style within the body of your document,    add
  2875.       the ----ccccllllaaaassssssss parameter to any HTML element:
  2876.  
  2877.           print h1({-class=>'Fancy'},'Welcome to the Party');
  2878.  
  2879.       Or define styles on the fly with the ----ssssttttyyyylllleeee parameter:
  2880.  
  2881.           print h1({-style=>'Color:    red;'},'Welcome    to Hell');
  2882.  
  2883.       You may also use the new ssssppppaaaannnn(((()))) element to apply a style to
  2884.       a section of text:
  2885.  
  2886.           print span({-style=>'Color: red;'},
  2887.              h1('Welcome to    Hell'),
  2888.              "Where    did that handbasket get    to?"
  2889.              );
  2890.  
  2891.       Note that you    must import the    ":html3" definitions to    have
  2892.       the ssssppppaaaannnn(((()))) method available.    Here's a quick and dirty
  2893.       example of using CSS's.  See the CSS specification at
  2894.       http://www.w3.org/pub/WWW/TR/Wd-css-1.html for more
  2895.       information.
  2896.  
  2897.           use CGI qw/:standard :html3/;
  2898.  
  2899.  
  2900.  
  2901.      Page 44                        (printed 10/23/98)
  2902.  
  2903.  
  2904.  
  2905.  
  2906.  
  2907.  
  2908.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  2909.  
  2910.  
  2911.  
  2912.           #here's a    stylesheet incorporated    directly into the page
  2913.           $newStyle=<<END;
  2914.           <!--
  2915.           P.Tip {
  2916.           margin-right:    50pt;
  2917.           margin-left: 50pt;
  2918.           color: red;
  2919.           }
  2920.           P.Alert {
  2921.           font-size: 30pt;
  2922.           font-family: sans-serif;
  2923.         color: red;
  2924.           }
  2925.           -->
  2926.           END
  2927.           print header();
  2928.           print start_html(    -title=>'CGI with Style',
  2929.                 -style=>{-src=>'http://www.capricorn.com/style/st1.css',
  2930.                      -code=>$newStyle}
  2931.                    );
  2932.           print h1('CGI with Style'),
  2933.             p({-class=>'Tip'},
  2934.               "Better read the cascading style sheet spec before playing with this!"),
  2935.             span({-style=>'color: magenta'},
  2936.              "Look Mom, no hands!",
  2937.              p(),
  2938.              "Whooo    wee!"
  2939.              );
  2940.           print end_html;
  2941.  
  2942.  
  2943.      DDDDEEEEBBBBUUUUGGGGGGGGIIIINNNNGGGG
  2944.       If you are running the script    from the command line or in
  2945.       the perl debugger, you can pass the script a list of
  2946.       keywords or parameter=value pairs on the command line    or
  2947.       from standard    input (you don't have to worry about tricking
  2948.       your script into reading from    environment variables).     You
  2949.       can pass keywords like this:
  2950.  
  2951.           your_script.pl keyword1 keyword2 keyword3
  2952.  
  2953.       or this:
  2954.  
  2955.          your_script.pl keyword1+keyword2+keyword3
  2956.  
  2957.       or this:
  2958.  
  2959.           your_script.pl name1=value1 name2=value2
  2960.  
  2961.       or this:
  2962.  
  2963.           your_script.pl name1=value1&name2=value2
  2964.  
  2965.  
  2966.  
  2967.      Page 45                        (printed 10/23/98)
  2968.  
  2969.  
  2970.  
  2971.  
  2972.  
  2973.  
  2974.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  2975.  
  2976.  
  2977.  
  2978.       or even as newline-delimited parameters on standard input.
  2979.  
  2980.       When debugging, you can use quotes and backslashes to    escape
  2981.       characters in    the familiar shell manner, letting you place
  2982.       spaces and other funny characters in your parameter=value
  2983.       pairs:
  2984.  
  2985.          your_script.pl "name1='I am a long    value'"    "name2=two\ words"
  2986.  
  2987.  
  2988.       DDDDUUUUMMMMPPPPIIIINNNNGGGG OOOOUUUUTTTT AAAALLLLLLLL TTTTHHHHEEEE NNNNAAAAMMMMEEEE////VVVVAAAALLLLUUUUEEEE PPPPAAAAIIIIRRRRSSSS
  2989.  
  2990.       The _d_u_m_p() method produces a string consisting of all    the
  2991.       query's name/value pairs formatted nicely as a nested    list.
  2992.       This is useful for debugging purposes:
  2993.  
  2994.           print $query->dump
  2995.  
  2996.  
  2997.       Produces something that looks    like:
  2998.  
  2999.           <UL>
  3000.           <LI>name1
  3001.           <UL>
  3002.           <LI>value1
  3003.           <LI>value2
  3004.           </UL>
  3005.           <LI>name2
  3006.           <UL>
  3007.           <LI>value1
  3008.           </UL>
  3009.           </UL>
  3010.  
  3011.       You can pass a value of 'true' to _d_u_m_p() in order to get it
  3012.       to print the results out as plain text, suitable for
  3013.       incorporating    into a <PRE> section.
  3014.  
  3015.       As a shortcut, as of version 1.56 you    can interpolate    the
  3016.       entire CGI object into a string and it will be replaced with
  3017.       the a    nice HTML dump shown above:
  3018.  
  3019.           $query=new CGI;
  3020.           print "<H2>Current Values</H2> $query\n";
  3021.  
  3022.  
  3023.      FFFFEEEETTTTCCCCHHHHIIIINNNNGGGG EEEENNNNVVVVIIIIRRRROOOONNNNMMMMEEEENNNNTTTT VVVVAAAARRRRIIIIAAAABBBBLLLLEEEESSSS
  3024.       Some of the more useful environment variables    can be fetched
  3025.       through this interface.  The methods are as follows:
  3026.  
  3027.       aaaacccccccceeeepppptttt(((())))
  3028.           Return a list    of MIME    types that the remote browser
  3029.           accepts. If you give this method a single argument
  3030.  
  3031.  
  3032.  
  3033.      Page 46                        (printed 10/23/98)
  3034.  
  3035.  
  3036.  
  3037.  
  3038.  
  3039.  
  3040.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  3041.  
  3042.  
  3043.  
  3044.           corresponding    to a MIME type,    as in
  3045.           $query->_a_c_c_e_p_t('text/html'), it will return a
  3046.           floating point value corresponding to    the browser's
  3047.           preference for this type from    0.0 (don't want) to
  3048.           1.0.    Glob types (e.g. text/*) in the    browser's
  3049.           accept list are handled correctly.
  3050.  
  3051.       rrrraaaawwww____ccccooooooookkkkiiiieeee(((())))
  3052.           Returns the HTTP_COOKIE variable, an HTTP extension
  3053.           implemented by Netscape browsers version 1.1 and
  3054.           higher.  Cookies have    a special format, and this
  3055.           method call just returns the raw form    (?cookie
  3056.           dough).  See _c_o_o_k_i_e()    for ways of setting and
  3057.           retrieving cooked cookies.
  3058.  
  3059.           Called with no parameters, _r_a_w__c_o_o_k_i_e() returns the
  3060.           packed cookie    structure.  You    can separate it    into
  3061.           individual cookies by    splitting on the character
  3062.           sequence "; ".  Called with the name of a cookie,
  3063.           retrieves the    uuuunnnneeeessssccccaaaappppeeeedddd form of the cookie.  You can
  3064.           use the regular _c_o_o_k_i_e() method to get the names, or
  3065.           use the _r_a_w__f_e_t_c_h() method from the CGI::Cookie
  3066.           module.
  3067.  
  3068.       uuuusssseeeerrrr____aaaaggggeeeennnntttt(((())))
  3069.           Returns the HTTP_USER_AGENT variable.     If you    give
  3070.           this method a    single argument, it will attempt to
  3071.           pattern match    on it, allowing    you to do something
  3072.           like $query->_u_s_e_r__a_g_e_n_t(netscape);
  3073.  
  3074.       ppppaaaatttthhhh____iiiinnnnffffoooo(((())))
  3075.           Returns additional path information from the script
  3076.           URL.    E.G. fetching /cgi-
  3077.           bin/your_script/additional/stuff will    result in
  3078.           $query->_p_a_t_h__i_n_f_o() returning    "additional/stuff".
  3079.  
  3080.           NOTE:    The Microsoft Internet Information Server is
  3081.           broken with respect to additional path information.
  3082.           If you use the Perl DLL library, the IIS server will
  3083.           attempt to execute the additional path information
  3084.           as a Perl script.  If    you use    the ordinary file
  3085.           associations mapping,    the path information will be
  3086.           present in the environment, but incorrect.  The best
  3087.           thing    to do is to avoid using    additional path
  3088.           information in CGI scripts destined for use with
  3089.           IIS.
  3090.  
  3091.       ppppaaaatttthhhh____ttttrrrraaaannnnssssllllaaaatttteeeedddd(((())))
  3092.           As per _p_a_t_h__i_n_f_o() but returns the additional    path
  3093.           information translated into a    physical path, e.g.
  3094.           "/usr/local/etc/httpd/htdocs/additional/stuff".
  3095.  
  3096.  
  3097.  
  3098.  
  3099.      Page 47                        (printed 10/23/98)
  3100.  
  3101.  
  3102.  
  3103.  
  3104.  
  3105.  
  3106.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  3107.  
  3108.  
  3109.  
  3110.           The Microsoft    IIS is broken with respect to the
  3111.           translated path as well.
  3112.  
  3113.       rrrreeeemmmmooootttteeee____hhhhoooosssstttt(((())))
  3114.           Returns either the remote host name or IP address.
  3115.           if the former    is unavailable.
  3116.  
  3117.      refering scripts.
  3118.       ssssccccrrrriiiipppptttt____nnnnaaaammmmeeee(((())))    Return the script name as a partial URL, for self-
  3119.  
  3120.       rrrreeeeffffeeeerrrreeeerrrr(((())))
  3121.           Return the URL of the    page the browser was viewing
  3122.           prior    to fetching your script.  Not available    for
  3123.           all browsers.
  3124.  
  3125.       aaaauuuutttthhhh____ttttyyyyppppeeee (((())))
  3126.           Return the authorization/verification    method in use
  3127.           for this script, if any.
  3128.  
  3129.       sssseeeerrrrvvvveeeerrrr____nnnnaaaammmmeeee (((())))
  3130.           Returns the name of the server, usually the
  3131.           machine's host name.
  3132.  
  3133.       vvvviiiirrrrttttuuuuaaaallll____hhhhoooosssstttt (((())))
  3134.           When using virtual hosts, returns the    name of    the
  3135.           host that the    browser    attempted to contact
  3136.  
  3137.       sssseeeerrrrvvvveeeerrrr____ssssooooffffttttwwwwaaaarrrreeee (((())))
  3138.           Returns the server software and version number.
  3139.  
  3140.       rrrreeeemmmmooootttteeee____uuuusssseeeerrrr (((())))
  3141.           Return the authorization/verification    name used for
  3142.           user verification, if    this script is protected.
  3143.  
  3144.       uuuusssseeeerrrr____nnnnaaaammmmeeee (((())))
  3145.           Attempt to obtain the    remote user's name, using a
  3146.           variety of different techniques.  This only works
  3147.           with older browsers such as Mosaic.  Netscape    does
  3148.           not reliably report the user name!
  3149.  
  3150.       rrrreeeeqqqquuuueeeesssstttt____mmmmeeeetttthhhhoooodddd(((())))
  3151.           Returns the method used to access your script,
  3152.           usually one of 'POST', 'GET' or 'HEAD'.
  3153.  
  3154.      UUUUSSSSIIIINNNNGGGG NNNNPPPPHHHH SSSSCCCCRRRRIIIIPPPPTTTTSSSS
  3155.       NPH, or "no-parsed-header", scripts bypass the server
  3156.       completely by    sending    the complete HTTP header directly to
  3157.       the browser.    This has slight    performance benefits, but is
  3158.       of most use for taking advantage of HTTP extensions that are
  3159.       not directly supported by your server, such as server    push
  3160.       and PICS headers.
  3161.  
  3162.  
  3163.  
  3164.  
  3165.      Page 48                        (printed 10/23/98)
  3166.  
  3167.  
  3168.  
  3169.  
  3170.  
  3171.  
  3172.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  3173.  
  3174.  
  3175.  
  3176.       Servers use a    variety    of conventions for designating CGI
  3177.       scripts as NPH.  Many    Unix servers look at the beginning of
  3178.       the script's name for    the prefix "nph-".  The    Macintosh
  3179.       WebSTAR server and Microsoft's Internet Information Server,
  3180.       in contrast, try to decide whether a program is an NPH
  3181.       script by examining the first    line of    script output.
  3182.  
  3183.       CGI.pm supports NPH scripts with a special NPH mode.    When
  3184.       in this mode,    CGI.pm will output the necessary extra header
  3185.       information when the _h_e_a_d_e_r()    and _r_e_d_i_r_e_c_t() methods are
  3186.       called.
  3187.  
  3188.       The Microsoft    Internet Information Server requires NPH mode.
  3189.       As of    version    2.30, CGI.pm will automatically    detect when
  3190.       the script is    running    under IIS and put itself into this
  3191.       mode.     You do    not need to do this manually, although it
  3192.       won't    hurt anything if you do.
  3193.  
  3194.       There    are a number of    ways to    put CGI.pm into    NPH mode:
  3195.  
  3196.       In the uuuusssseeee statement
  3197.           Simply add the "-nph"    pragmato the list of symbols
  3198.           to be    imported into your script:
  3199.  
  3200.             use CGI    qw(:standard -nph)
  3201.  
  3202.  
  3203.       By calling the nnnnpppphhhh(((()))) method:
  3204.           Call nnnnpppphhhh(((()))) with a non-zero parameter at any point
  3205.           after    using CGI.pm in    your program.
  3206.  
  3207.             CGI->nph(1)
  3208.  
  3209.  
  3210.      statements:
  3211.       By using ----nnnnpppphhhh    parameters in the hhhheeeeaaaaddddeeeerrrr(((()))) and rrrreeeeddddiiiirrrreeeecccctttt(((())))
  3212.  
  3213.             print $q->header(-nph=>1);
  3214.  
  3215.  
  3216.      SSSSeeeerrrrvvvveeeerrrr PPPPuuuusssshhhh
  3217.       CGI.pm provides three    simple functions for producing
  3218.       multipart documents of the type needed to implement server
  3219.       push.     These functions were graciously provided by Ed    Jordan
  3220.       <ed@fidalgo.net>.  To    import these into your namespace, you
  3221.       must import the ":push" set.    You are    also advised to    put
  3222.       the script into NPH mode and to set $| to 1 to avoid
  3223.       buffering problems.
  3224.  
  3225.       Here is a simple script that demonstrates server push:
  3226.  
  3227.  
  3228.  
  3229.  
  3230.  
  3231.      Page 49                        (printed 10/23/98)
  3232.  
  3233.  
  3234.  
  3235.  
  3236.  
  3237.  
  3238.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  3239.  
  3240.  
  3241.  
  3242.         #!/usr/local/bin/perl
  3243.         use    CGI qw/:push -nph/;
  3244.         $| = 1;
  3245.         print multipart_init(-boundary=>'----------------here we go!');
  3246.         while (1) {
  3247.         print multipart_start(-type=>'text/plain'),
  3248.               "The current time    is ",scalar(localtime),"\n",
  3249.               multipart_end;
  3250.         sleep 1;
  3251.         }
  3252.  
  3253.       This script initializes server push by calling
  3254.       mmmmuuuullllttttiiiippppaaaarrrrtttt____iiiinnnniiiitttt(((()))).  It    then enters an infinite    loop in    which
  3255.       it begins a new multipart section by calling
  3256.       mmmmuuuullllttttiiiippppaaaarrrrtttt____ssssttttaaaarrrrtttt(((()))), prints the    current    local time, and    ends a
  3257.       multipart section with mmmmuuuullllttttiiiippppaaaarrrrtttt____eeeennnndddd(((()))).  It then sleeps a
  3258.       second, and begins again.
  3259.  
  3260.       multipart_init()       multipart_init(-boundary=>$boundary);
  3261.           Initialize the multipart system.  The    -boundary
  3262.           argument specifies what MIME boundary    string to use
  3263.           to separate parts of the document.  If not provided,
  3264.           CGI.pm chooses a reasonable boundary for you.
  3265.  
  3266.       multipart_start()
  3267.  
  3268.             multipart_start(-type=>$type)
  3269.  
  3270.           Start    a new part of the multipart document using the
  3271.           specified MIME type.    If not specified, text/html is
  3272.           assumed.
  3273.  
  3274.       multipart_end()
  3275.  
  3276.             multipart_end()
  3277.  
  3278.           End a    part.  You must    remember to call
  3279.           _m_u_l_t_i_p_a_r_t__e_n_d() once for each    _m_u_l_t_i_p_a_r_t__s_t_a_r_t().
  3280.  
  3281.           Users    interested in server push applications should
  3282.           also have a look at the CGI::Push module.
  3283.  
  3284.      AAAAvvvvooooiiiiddddiiiinnnngggg DDDDeeeennnniiiiaaaallll ooooffff    SSSSeeeerrrrvvvviiiicccceeee    AAAAttttttttaaaacccckkkkssss
  3285.       A potential problem with CGI.pm is that, by default, it
  3286.       attempts to process form POSTings no matter how large    they
  3287.       are.    A wily hacker could attack your    site by    sending    a CGI
  3288.       script a huge    POST of    many megabytes.     CGI.pm    will attempt
  3289.       to read the entire POST into a variable, growing hugely in
  3290.       size until it    runs out of memory.  While the script attempts
  3291.       to allocate the memory the system may    slow down
  3292.       dramatically.     This is a form    of denial of service attack.
  3293.  
  3294.  
  3295.  
  3296.  
  3297.      Page 50                        (printed 10/23/98)
  3298.  
  3299.  
  3300.  
  3301.  
  3302.  
  3303.  
  3304.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  3305.  
  3306.  
  3307.  
  3308.       Another possible attack is for the remote user to force
  3309.       CGI.pm to accept a huge file upload.    CGI.pm will accept the
  3310.       upload and store it in a temporary directory even if your
  3311.       script doesn't expect    to receive an uploaded file.  CGI.pm
  3312.       will delete the file automatically when it terminates, but
  3313.       in the meantime the remote user may have filled up the
  3314.       server's disk    space, causing problems    for other programs.
  3315.  
  3316.       The best way to avoid    denial of service attacks is to    limit
  3317.       the amount of    memory,    CPU time and disk space    that CGI
  3318.       scripts can use.  Some Web servers come with built-in
  3319.       facilities to    accomplish this. In other cases, you can use
  3320.       the shell _l_i_m_i_t or _u_l_i_m_i_t commands to    put ceilings on    CGI
  3321.       resource usage.
  3322.  
  3323.       CGI.pm also has some simple built-in protections against
  3324.       denial of service attacks, but you must activate them    before
  3325.       you can use them.  These take    the form of two    global
  3326.       variables in the CGI name space:
  3327.  
  3328.       $$$$CCCCGGGGIIII::::::::PPPPOOOOSSSSTTTT____MMMMAAAAXXXX
  3329.           If set to a non-negative integer, this variable puts
  3330.           a ceiling on the size    of POSTings, in    bytes.    If
  3331.           CGI.pm detects a POST    that is    greater    than the
  3332.           ceiling, it will immediately exit with an error
  3333.           message.  This value will affect both    ordinary POSTs
  3334.           and multipart    POSTs, meaning that it limits the
  3335.           maximum size of file uploads as well.     You should
  3336.           set this to a    reasonably high    value, such as 1
  3337.           megabyte.
  3338.  
  3339.       $$$$CCCCGGGGIIII::::::::DDDDIIIISSSSAAAABBBBLLLLEEEE____UUUUPPPPLLLLOOOOAAAADDDDSSSS
  3340.           If set to a non-zero value, this will    disable    file
  3341.           uploads completely.  Other fill-out form values will
  3342.           work as usual.
  3343.  
  3344.           You can use these variables in either    of two ways.
  3345.  
  3346.       1111.... OOOOnnnn    aaaa ssssccccrrrriiiipppptttt----bbbbyyyy----ssssccccrrrriiiipppptttt bbbbaaaassssiiiissss
  3347.           Set the variable at the top of the script, right
  3348.           after    the "use" statement:
  3349.  
  3350.               use CGI qw/:standard/;
  3351.               use CGI::Carp 'fatalsToBrowser';
  3352.               $CGI::POST_MAX=1024 * 100;  # max    100K posts
  3353.               $CGI::DISABLE_UPLOADS = 1;  # no uploads
  3354.  
  3355.  
  3356.       2222.... GGGGlllloooobbbbaaaallllllllyyyy ffffoooorrrr aaaallllllll ssssccccrrrriiiippppttttssss
  3357.           Open up CGI.pm, find the definitions for $POST_MAX
  3358.           and $DISABLE_UPLOADS,    and set    them to    the desired
  3359.           values.  You'll find them towards the    top of the
  3360.  
  3361.  
  3362.  
  3363.      Page 51                        (printed 10/23/98)
  3364.  
  3365.  
  3366.  
  3367.  
  3368.  
  3369.  
  3370.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  3371.  
  3372.  
  3373.  
  3374.           file in a subroutine named _i_n_i_t_i_a_l_i_z_e__g_l_o_b_a_l_s().
  3375.  
  3376.           Since    an attempt to send a POST larger than
  3377.           $POST_MAX bytes will cause a fatal error, you    might
  3378.           want to use CGI::Carp    to echo    the fatal error
  3379.           message to the browser window    as shown in the
  3380.           example above.  Otherwise the    remote user will see
  3381.           only a generic "Internal Server" error message.  See
  3382.           the the _C_G_I::_C_a_r_p manpage manual page    for more
  3383.           details.
  3384.  
  3385.      CCCCOOOOMMMMPPPPAAAATTTTIIIIBBBBIIIILLLLIIIITTTTYYYY WWWWIIIITTTTHHHH    CCCCGGGGIIII----LLLLIIIIBBBB....PPPPLLLL
  3386.       To make it easier to port existing programs that use cgi-
  3387.       lib.pl the compatibility routine "ReadParse" is provided.
  3388.       Porting is simple:
  3389.  
  3390.       OLD VERSION
  3391.           require "cgi-lib.pl";
  3392.           &ReadParse;
  3393.           print "The value of the antique is $in{antique}.\n";
  3394.  
  3395.       NEW VERSION
  3396.           use CGI;
  3397.           CGI::ReadParse
  3398.           print "The value of the antique is $in{antique}.\n";
  3399.  
  3400.       CGI.pm's _R_e_a_d_P_a_r_s_e() routine creates a tied variable named
  3401.       %in, which can be accessed to    obtain the query variables.
  3402.       Like ReadParse, you can also provide your own    variable.
  3403.       Infrequently used features of    ReadParse, such    as the
  3404.       creation of @in and $in variables, are not supported.
  3405.  
  3406.       Once you use ReadParse, you can retrieve the query object
  3407.       itself this way:
  3408.  
  3409.           $q = $in{CGI};
  3410.           print $q->textfield(-name=>'wow',
  3411.                   -value=>'does    this really work?');
  3412.  
  3413.       This allows you to start using the more interesting features
  3414.       of CGI.pm without rewriting your old scripts from scratch.
  3415.  
  3416.      AAAAUUUUTTTTHHHHOOOORRRR IIIINNNNFFFFOOOORRRRMMMMAAAATTTTIIIIOOOONNNN
  3417.       Copyright 1995-1997, Lincoln D. Stein.  All rights reserved.
  3418.       It may be used and modified freely, but I do request that
  3419.       this copyright notice    remain attached    to the file.  You may
  3420.       modify this module as    you wish, but if you redistribute a
  3421.       modified version, please attach a note listing the
  3422.       modifications    you have made.
  3423.  
  3424.       Address bug reports and comments to:
  3425.       lstein@genome.wi.mit.edu
  3426.  
  3427.  
  3428.  
  3429.      Page 52                        (printed 10/23/98)
  3430.  
  3431.  
  3432.  
  3433.  
  3434.  
  3435.  
  3436.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  3437.  
  3438.  
  3439.  
  3440.      CCCCRRRREEEEDDDDIIIITTTTSSSS
  3441.       Thanks very much to:
  3442.  
  3443.       Matt Heffron (heffron@falstaff.css.beckman.com)
  3444.  
  3445.       James    Taylor (james.taylor@srs.gov)
  3446.  
  3447.       Scott    Anguish    <sanguish@digifix.com>
  3448.  
  3449.       Mike Jewell (mlj3u@virginia.edu)
  3450.  
  3451.       Timothy Shimmin (tes@kbs.citri.edu.au)
  3452.  
  3453.       Joergen Haegg    (jh@axis.se)
  3454.  
  3455.       Laurent Delfosse (delfosse@csgrad1.cs.wvu.edu)
  3456.  
  3457.       Richard Resnick (applepi1@aol.com)
  3458.  
  3459.       Craig    Bishop (csb@barwonwater.vic.gov.au)
  3460.  
  3461.       Tony Curtis (tc@vcpc.univie.ac.at)
  3462.  
  3463.       Tim Bunce (Tim.Bunce@ig.co.uk)
  3464.  
  3465.       Tom Christiansen (tchrist@convex.com)
  3466.  
  3467.       Andreas Koenig (k@franz.ww.TU-Berlin.DE)
  3468.  
  3469.       Tim MacKenzie    (Tim.MacKenzie@fulcrum.com.au)
  3470.  
  3471.       Kevin    B. Hendricks (kbhend@dogwood.tyler.wm.edu)
  3472.  
  3473.       Stephen Dahmen (joyfire@inxpress.net)
  3474.  
  3475.       Ed Jordan (ed@fidalgo.net)
  3476.  
  3477.       David    Alan Pisoni (david@cnation.com)
  3478.  
  3479.       Doug MacEachern (dougm@opengroup.org)
  3480.  
  3481.       Robin    Houston    (robin@oneworld.org)
  3482.  
  3483.       ...and many many more...
  3484.           for suggestions and bug fixes.
  3485.  
  3486.      AAAA CCCCOOOOMMMMPPPPLLLLEEEETTTTEEEE    EEEEXXXXAAAAMMMMPPPPLLLLEEEE    OOOOFFFF AAAA SSSSIIIIMMMMPPPPLLLLEEEE FFFFOOOORRRRMMMM----BBBBAAAASSSSEEEEDDDD SSSSCCCCRRRRIIIIPPPPTTTT
  3487.           #!/usr/local/bin/perl
  3488.  
  3489.           use CGI;
  3490.  
  3491.           $query = new CGI;
  3492.  
  3493.  
  3494.  
  3495.      Page 53                        (printed 10/23/98)
  3496.  
  3497.  
  3498.  
  3499.  
  3500.  
  3501.  
  3502.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  3503.  
  3504.  
  3505.  
  3506.  
  3507.  
  3508.  
  3509.  
  3510.  
  3511.  
  3512.  
  3513.  
  3514.  
  3515.  
  3516.  
  3517.  
  3518.  
  3519.  
  3520.  
  3521.  
  3522.  
  3523.  
  3524.  
  3525.  
  3526.  
  3527.  
  3528.  
  3529.  
  3530.  
  3531.  
  3532.  
  3533.  
  3534.  
  3535.  
  3536.  
  3537.  
  3538.  
  3539.  
  3540.  
  3541.  
  3542.  
  3543.  
  3544.  
  3545.  
  3546.  
  3547.  
  3548.  
  3549.  
  3550.  
  3551.  
  3552.  
  3553.  
  3554.  
  3555.  
  3556.  
  3557.  
  3558.  
  3559.  
  3560.  
  3561.      Page 54                        (printed 10/23/98)
  3562.  
  3563.  
  3564.  
  3565.  
  3566.  
  3567.  
  3568.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  3569.  
  3570.  
  3571.  
  3572.           print    $query->header;
  3573.           print    $query->start_html("Example CGI.pm Form");
  3574.           print    "<H1> Example CGI.pm Form</H1>\n";
  3575.           &print_prompt($query);
  3576.           &do_work($query);
  3577.           &print_tail;
  3578.           print    $query->end_html;
  3579.  
  3580.           sub print_prompt {
  3581.              my($query)    = @_;
  3582.  
  3583.              print $query->startform;
  3584.              print "<EM>What's your name?</EM><BR>";
  3585.              print $query->textfield('name');
  3586.              print $query->checkbox('Not my real name');
  3587.  
  3588.              print "<P><EM>Where can you find English Sparrows?</EM><BR>";
  3589.              print $query->checkbox_group(
  3590.                        -name=>'Sparrow locations',
  3591.                        -values=>[England,France,Spain,Asia,Hoboken],
  3592.                        -linebreak=>'yes',
  3593.                        -defaults=>[England,Asia]);
  3594.  
  3595.              print "<P><EM>How far can they fly?</EM><BR>",
  3596.               $query->radio_group(
  3597.                   -name=>'how far',
  3598.                   -values=>['10    ft','1 mile','10 miles','real far'],
  3599.                   -default=>'1 mile');
  3600.  
  3601.              print "<P><EM>What's your favorite    color?</EM>  ";
  3602.              print $query->popup_menu(-name=>'Color',
  3603.                           -values=>['black','brown','red','yellow'],
  3604.                           -default=>'red');
  3605.  
  3606.              print $query->hidden('Reference','Monty Python and    the Holy Grail');
  3607.  
  3608.              print "<P><EM>What    have you got there?</EM><BR>";
  3609.              print $query->scrolling_list(
  3610.                    -name=>'possessions',
  3611.                    -values=>['A    Coconut','A Grail','An Icon',
  3612.                          'A    Sword','A Ticket'],
  3613.                    -size=>5,
  3614.                    -multiple=>'true');
  3615.  
  3616.              print "<P><EM>Any parting comments?</EM><BR>";
  3617.              print $query->textarea(-name=>'Comments',
  3618.                         -rows=>10,
  3619.                         -columns=>50);
  3620.  
  3621.              print "<P>",$query->reset;
  3622.              print $query->submit('Action','Shout');
  3623.              print $query->submit('Action','Scream');
  3624.  
  3625.  
  3626.  
  3627.      Page 55                        (printed 10/23/98)
  3628.  
  3629.  
  3630.  
  3631.  
  3632.  
  3633.  
  3634.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  3635.  
  3636.  
  3637.  
  3638.              print $query->endform;
  3639.              print "<HR>\n";
  3640.           }
  3641.  
  3642.           sub do_work {
  3643.              my($query)    = @_;
  3644.              my(@values,$key);
  3645.  
  3646.              print "<H2>Here are the current settings in this form</H2>";
  3647.  
  3648.              foreach $key ($query->param) {
  3649.             print "<STRONG>$key</STRONG> ->    ";
  3650.             @values    = $query->param($key);
  3651.             print join(", ",@values),"<BR>\n";
  3652.             }
  3653.           }
  3654.  
  3655.           sub print_tail {
  3656.              print <<END;
  3657.           <HR>
  3658.           <ADDRESS>Lincoln D. Stein</ADDRESS><BR>
  3659.           <A HREF="/">Home Page</A>
  3660.           END
  3661.           }
  3662.  
  3663.  
  3664.      BBBBUUUUGGGGSSSS
  3665.       This module has grown    large and monolithic.  Furthermore
  3666.       it's doing many things, such as handling URLs, parsing CGI
  3667.       input, writing HTML, etc., that are also done    in the LWP
  3668.       modules. It should be    discarded in favor of the CGI::*
  3669.       modules, but somehow I continue to work on it.
  3670.  
  3671.       Note that the    code is    truly contorted    in order to avoid
  3672.       spurious warnings when programs are run with the ----wwww switch.
  3673.  
  3674.      SSSSEEEEEEEE AAAALLLLSSSSOOOO
  3675.       the _C_G_I::_C_a_r_p    manpage, the _U_R_I::_U_R_L manpage, the
  3676.       _C_G_I::_R_e_q_u_e_s_t manpage,    the _C_G_I::_M_i_n_i_S_v_r manpage, the
  3677.       _C_G_I::_B_a_s_e manpage, the _C_G_I::_F_o_r_m manpage, the    _C_G_I::_A_p_a_c_h_e
  3678.       manpage, the _C_G_I::_S_w_i_t_c_h manpage, the    _C_G_I::_P_u_s_h manpage, the
  3679.       _C_G_I::_F_a_s_t manpage
  3680.  
  3681.  
  3682.  
  3683.  
  3684.  
  3685.  
  3686.  
  3687.  
  3688.  
  3689.  
  3690.  
  3691.  
  3692.  
  3693.      Page 56                        (printed 10/23/98)
  3694.  
  3695.  
  3696.  
  3697.  
  3698.  
  3699.  
  3700.      CCCCGGGGIIII((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        CCCCGGGGIIII((((3333))))
  3701.  
  3702.  
  3703.  
  3704.  
  3705.  
  3706.  
  3707.  
  3708.  
  3709.  
  3710.  
  3711.  
  3712.  
  3713.  
  3714.  
  3715.  
  3716.  
  3717.  
  3718.  
  3719.  
  3720.  
  3721.  
  3722.  
  3723.  
  3724.  
  3725.  
  3726.  
  3727.  
  3728.  
  3729.  
  3730.  
  3731.  
  3732.  
  3733.  
  3734.  
  3735.  
  3736.  
  3737.  
  3738.  
  3739.  
  3740.  
  3741.  
  3742.  
  3743.  
  3744.  
  3745.  
  3746.  
  3747.  
  3748.  
  3749.  
  3750.  
  3751.  
  3752.  
  3753.  
  3754.  
  3755.  
  3756.      Page 57                        (printed 10/23/98)
  3757.  
  3758.  
  3759.  
  3760.  
  3761.  
  3762.  
  3763.